Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

The Linear API client.

Implementations§

Source§

impl Client

Source

pub fn from_token(token: impl Into<String>) -> Result<Self, LinearError>

Create a client with an explicit API token.

Source

pub fn from_env() -> Result<Self, LinearError>

Create a client from the LINEAR_API_TOKEN environment variable.

Source

pub fn from_token_file(path: &Path) -> Result<Self, LinearError>

Create a client from a token file at the given path.

Source

pub async fn execute<T: DeserializeOwned>( &self, query: &str, variables: Value, data_path: &str, ) -> Result<T, LinearError>

Execute a GraphQL query and extract a single object from the response.

Source

pub async fn execute_connection<T: DeserializeOwned>( &self, query: &str, variables: Value, data_path: &str, ) -> Result<Connection<T>, LinearError>

Execute a GraphQL query and extract a Connection from the response.

Source

pub async fn query<T: DeserializeOwned + GraphQLFields>( &self, field: &str, ) -> Result<T, LinearError>

Execute a typed query using the type’s GraphQLFields implementation.

Builds the query from T::selection() — define a struct with only the fields you need for zero-overfetch queries.

#[derive(Deserialize)]
struct MyViewer { name: Option<String>, email: Option<String> }

impl GraphQLFields for MyViewer {
    fn selection() -> String { "name email".into() }
}

let me: MyViewer = client.query::<MyViewer>("viewer").await?;
Source

pub async fn query_connection<T: DeserializeOwned + GraphQLFields>( &self, field: &str, ) -> Result<Connection<T>, LinearError>

Execute a typed connection query using the node type’s GraphQLFields implementation.

Builds { field { nodes { <T::selection()> } pageInfo { ... } } }.

Source§

impl Client

Source

pub fn workflow_states<T>(&self) -> WorkflowStatesQueryBuilder<'_, T>

All issue workflow states (issue statuses). Returns a paginated list of workflow states visible to the authenticated user, across all teams they have access to.

Full type: WorkflowState

Source

pub fn users<T>(&self) -> UsersQueryBuilder<'_, T>

All users in the workspace. Supports filtering, sorting, and pagination.

Full type: User

Source

pub async fn whoami<T: DeserializeOwned + GraphQLFields<FullType = User>>( &self, ) -> Result<T, LinearError>

The currently authenticated user making the API request.

Full type: User

Source

pub fn projects<T>(&self) -> ProjectsQueryBuilder<'_, T>

Returns all projects in the workspace, with optional filtering and sorting.

Full type: Project

Source

pub async fn project<T: DeserializeOwned + GraphQLFields<FullType = Project>>( &self, id: String, ) -> Result<T, LinearError>

Returns a single project by its identifier or URL slug.

Full type: Project

Source

pub fn teams<T>(&self) -> TeamsQueryBuilder<'_, T>

All teams whose issues the user can access. This includes public teams and private teams the user is a member of. This may differ from administrableTeams, which returns teams whose settings the user can change but whose issues they don’t necessarily have access to.

Full type: Team

Source

pub async fn team<T: DeserializeOwned + GraphQLFields<FullType = Team>>( &self, id: String, ) -> Result<T, LinearError>

Fetches a specific team by its ID.

Full type: Team

Source

pub fn search_issues<T>( &self, term: impl Into<String>, ) -> SearchIssuesQueryBuilder<'_, T>

Search issues by text query using full-text and vector search. Results are ranked by relevance unless an orderBy parameter is specified. Supports optional issue filters and comment inclusion. Rate-limited to 30 requests per minute.

Full type: IssueSearchResult

Source

pub fn project_statuses<T>(&self) -> ProjectStatusesQueryBuilder<'_, T>

Returns all project statuses in the workspace.

Full type: ProjectStatus

Source

pub fn project_milestones<T>(&self) -> ProjectMilestonesQueryBuilder<'_, T>

Returns all project milestones in the workspace, with optional filtering.

Full type: ProjectMilestone

Source

pub async fn project_milestone<T: DeserializeOwned + GraphQLFields<FullType = ProjectMilestone>>( &self, id: String, ) -> Result<T, LinearError>

Returns a single project milestone by its identifier.

Full type: ProjectMilestone

Source

pub fn project_labels<T>(&self) -> ProjectLabelsQueryBuilder<'_, T>

Returns all project labels in the workspace, with optional filtering.

Full type: ProjectLabel

Source

pub fn issues<T>(&self) -> IssuesQueryBuilder<'_, T>

All issues. Returns a paginated list of issues visible to the authenticated user. Can be filtered by various criteria including team, assignee, state, labels, project, and cycle.

Full type: Issue

Source

pub async fn issue<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, id: String, ) -> Result<T, LinearError>

One specific issue, looked up by its unique identifier.

Full type: Issue

Find issue based on the VCS branch name.

Full type: Issue

Source

pub fn issue_relations<T>(&self) -> IssueRelationsQueryBuilder<'_, T>

All issue relations. Returns a paginated list of all issue relations (blocks, blocked by, relates to, duplicates) visible to the authenticated user.

Full type: IssueRelation

Source

pub async fn issue_relation<T: DeserializeOwned + GraphQLFields<FullType = IssueRelation>>( &self, id: String, ) -> Result<T, LinearError>

One specific issue relation, looked up by its unique identifier.

Full type: IssueRelation

Source

pub fn issue_labels<T>(&self) -> IssueLabelsQueryBuilder<'_, T>

All issue labels. Returns a paginated list of labels visible to the authenticated user, including both workspace-level and team-scoped labels.

Full type: IssueLabel

Source

pub fn documents<T>(&self) -> DocumentsQueryBuilder<'_, T>

All documents the user has access to in the workspace.

Full type: Document

Source

pub async fn document<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, id: String, ) -> Result<T, LinearError>

A specific document by ID or slug.

Full type: Document

Source

pub fn cycles<T>(&self) -> CyclesQueryBuilder<'_, T>

All cycles accessible to the user.

Full type: Cycle

Source

pub async fn cycle<T: DeserializeOwned + GraphQLFields<FullType = Cycle>>( &self, id: String, ) -> Result<T, LinearError>

One specific cycle, looked up by ID or slug.

Full type: Cycle

Source

pub async fn file_upload( &self, meta_data: Option<Value>, make_public: Option<bool>, size: i64, content_type: String, filename: String, ) -> Result<Value, LinearError>

XHR request payload to upload an images, video and other attachments directly to Linear’s cloud storage.

Source

pub async fn image_upload_from_url( &self, url: String, ) -> Result<Value, LinearError>

Upload an image from an URL to Linear.

Source

pub async fn project_create<T: DeserializeOwned + GraphQLFields<FullType = Project>>( &self, slack_channel_name: Option<String>, input: ProjectCreateInput, ) -> Result<T, LinearError>

Creates a new project.

Full type: Project

Source

pub async fn project_update<T: DeserializeOwned + GraphQLFields<FullType = Project>>( &self, input: ProjectUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a project.

Full type: Project

Source

pub async fn project_delete<T: DeserializeOwned + GraphQLFields<FullType = Project>>( &self, id: String, ) -> Result<T, LinearError>

Deletes (trashes) a project. The project can be restored later with projectUnarchive.

Full type: Project

Source

pub async fn team_create<T: DeserializeOwned + GraphQLFields<FullType = Team>>( &self, copy_settings_from_team_id: Option<String>, input: TeamCreateInput, ) -> Result<T, LinearError>

Creates a new team. The user who creates the team will automatically be added as a member and owner of the newly created team. Default workflow states, labels, and other team resources are created alongside the team.

Full type: Team

Source

pub async fn team_update<T: DeserializeOwned + GraphQLFields<FullType = Team>>( &self, mapping: Option<InheritanceEntityMapping>, input: TeamUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a team’s settings, properties, or configuration. Requires team owner or workspace admin permissions for most changes.

Full type: Team

Source

pub async fn team_delete(&self, id: String) -> Result<Value, LinearError>

Archives a team and schedules its data for deletion. Requires team owner or workspace admin permissions.

Source

pub async fn team_membership_create<T: DeserializeOwned + GraphQLFields<FullType = TeamMembership>>( &self, input: TeamMembershipCreateInput, ) -> Result<T, LinearError>

Creates a new team membership, adding a user to a team. Validates that the user is not already a member, the team is not archived or retired, and the requesting user has permission to add members.

Full type: TeamMembership

Source

pub async fn team_membership_delete( &self, also_leave_parent_teams: Option<bool>, id: String, ) -> Result<Value, LinearError>

Deletes a team membership, removing the user from the team. Users can remove their own membership, or team owners and workspace admins can remove other members.

Source

pub async fn project_milestone_create<T: DeserializeOwned + GraphQLFields<FullType = ProjectMilestone>>( &self, input: ProjectMilestoneCreateInput, ) -> Result<T, LinearError>

Creates a new project milestone.

Full type: ProjectMilestone

Source

pub async fn project_milestone_update<T: DeserializeOwned + GraphQLFields<FullType = ProjectMilestone>>( &self, input: ProjectMilestoneUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a project milestone.

Full type: ProjectMilestone

Source

pub async fn project_milestone_delete( &self, id: String, ) -> Result<Value, LinearError>

Deletes a project milestone.

Source

pub async fn issue_create<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, input: IssueCreateInput, ) -> Result<T, LinearError>

Creates a new issue.

Full type: Issue

Source

pub async fn issue_update<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, input: IssueUpdateInput, id: String, ) -> Result<T, LinearError>

Updates an issue.

Full type: Issue

Source

pub async fn issue_batch_update<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, input: IssueUpdateInput, ids: Vec<String>, ) -> Result<Vec<T>, LinearError>

Updates multiple issues at once.

Full type: Issue

Source

pub async fn issue_archive<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, trash: Option<bool>, id: String, ) -> Result<T, LinearError>

Archives an issue.

Full type: Issue

Source

pub async fn issue_unarchive<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, id: String, ) -> Result<T, LinearError>

Unarchives an issue.

Full type: Issue

Source

pub async fn issue_delete<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, permanently_delete: Option<bool>, id: String, ) -> Result<T, LinearError>

Deletes (trashes) an issue.

Full type: Issue

Source

pub async fn issue_relation_create<T: DeserializeOwned + GraphQLFields<FullType = IssueRelation>>( &self, override_created_at: Option<Value>, input: IssueRelationCreateInput, ) -> Result<T, LinearError>

Creates a new issue relation.

Full type: IssueRelation

Source

pub async fn issue_relation_delete( &self, id: String, ) -> Result<Value, LinearError>

Deletes an issue relation.

Source

pub async fn issue_label_create<T: DeserializeOwned + GraphQLFields<FullType = IssueLabel>>( &self, replace_team_labels: Option<bool>, input: IssueLabelCreateInput, ) -> Result<T, LinearError>

Creates a new label.

Full type: IssueLabel

Source

pub async fn issue_label_update<T: DeserializeOwned + GraphQLFields<FullType = IssueLabel>>( &self, replace_team_labels: Option<bool>, input: IssueLabelUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a label.

Full type: IssueLabel

Source

pub async fn issue_label_delete(&self, id: String) -> Result<Value, LinearError>

Deletes an issue label.

Source

pub async fn document_create<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, input: DocumentCreateInput, ) -> Result<T, LinearError>

Creates a new document.

Full type: Document

Source

pub async fn document_update<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, input: DocumentUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a document.

Full type: Document

Source

pub async fn document_delete<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, id: String, ) -> Result<T, LinearError>

Deletes (trashes) a document. The document is marked as trashed and archived, but not permanently removed.

Full type: Document

Source

pub async fn comment_create<T: DeserializeOwned + GraphQLFields<FullType = Comment>>( &self, input: CommentCreateInput, ) -> Result<T, LinearError>

Creates a new comment.

Full type: Comment

Source

pub async fn comment_update<T: DeserializeOwned + GraphQLFields<FullType = Comment>>( &self, skip_edited_at: Option<bool>, input: CommentUpdateInput, id: String, ) -> Result<T, LinearError>

Updates a comment.

Full type: Comment

Source

pub async fn comment_delete(&self, id: String) -> Result<Value, LinearError>

Deletes a comment.

Source

pub async fn comment_resolve<T: DeserializeOwned + GraphQLFields<FullType = Comment>>( &self, resolving_comment_id: Option<String>, id: String, ) -> Result<T, LinearError>

Resolves a comment thread. Marks the root comment as resolved by the current user.

Full type: Comment

Source

pub async fn comment_unresolve<T: DeserializeOwned + GraphQLFields<FullType = Comment>>( &self, id: String, ) -> Result<T, LinearError>

Unresolves a previously resolved comment thread. Clears the resolved state on the root comment.

Full type: Comment

Source§

impl Client

Source

pub async fn download_url( &self, url: &str, ) -> Result<DownloadResult, LinearError>

Download a file from a URL.

Handles Linear’s signed/expiring CDN URLs (e.g. https://uploads.linear.app/...) as well as any other publicly accessible URL. Returns the raw bytes and content type so the caller can write them to disk or process them further.

§Errors

Returns LinearError::HttpError if the server responds with a non-2xx status, or LinearError::Network if the request fails at the transport level.

§Example
let client = lineark_sdk::Client::from_env()?;
let result = client.download_url("https://uploads.linear.app/...").await?;
std::fs::write("output.png", &result.bytes).unwrap();
Source

pub async fn upload_file( &self, filename: &str, content_type: &str, bytes: Vec<u8>, make_public: bool, ) -> Result<UploadResult, LinearError>

Upload a file to Linear’s cloud storage.

This is a two-step process:

  1. Call the fileUpload GraphQL mutation to obtain a signed upload URL and required headers from Linear.
  2. PUT the raw file bytes to that signed URL (a Google Cloud Storage endpoint).

On success, returns an UploadResult containing the permanent asset_url that can be referenced in issue descriptions, comments, or attachments.

§Arguments
  • filename — The original filename (e.g. "screenshot.png"). Linear uses this for display and content-type inference on its side.
  • content_type — MIME type of the file (e.g. "image/png").
  • bytes — The raw file content.
  • make_public — If true, the uploaded file will be publicly accessible without authentication.
§Errors

Returns an error if the fileUpload mutation fails, if the signed URL upload fails, or if the response is missing expected fields.

§Example
let client = lineark_sdk::Client::from_env()?;
let bytes = std::fs::read("screenshot.png").unwrap();
let result = client
    .upload_file("screenshot.png", "image/png", bytes, false)
    .await?;
println!("Uploaded to: {}", result.asset_url);

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> FieldCompatible<T> for T