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_file() -> Result<Self, LinearError>

Create a client from the ~/.linear_api_token file.

Source

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

Create a client by auto-detecting the token (env -> file).

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.

Full type: WorkflowState

Source

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

All users for the organization.

Full type: User

Source

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

The currently authenticated user.

Full type: User

Source

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

All projects.

Full type: Project

Source

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

One specific project.

Full type: Project

Source

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

All teams whose issues can be accessed by the user. This might be different from administrableTeams, which also includes teams whose settings can be changed by the user.

Full type: Team

Source

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

One specific team.

Full type: Team

Source

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

Search issues.

Full type: IssueSearchResult

Source

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

All milestones for the project.

Full type: ProjectMilestone

Source

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

One specific project milestone.

Full type: ProjectMilestone

Source

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

All issues.

Full type: Issue

Source

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

One specific issue.

Full type: Issue

Source

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

All issue relationships.

Full type: IssueRelation

Source

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

One specific issue relation.

Full type: IssueRelation

Source

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

All issue labels.

Full type: IssueLabel

Source

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

All documents in the workspace.

Full type: Document

Source

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

One specific document.

Full type: Document

Source

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

All cycles.

Full type: Cycle

Source

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

One specific cycle.

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.

Full type: Project

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_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 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.

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§

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::auto()?;
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::auto()?;
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§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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