pub struct Client { /* private fields */ }Expand description
The Linear API client.
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_token(token: impl Into<String>) -> Result<Self, LinearError>
pub fn from_token(token: impl Into<String>) -> Result<Self, LinearError>
Create a client with an explicit API token.
Sourcepub fn from_env() -> Result<Self, LinearError>
pub fn from_env() -> Result<Self, LinearError>
Create a client from the LINEAR_API_TOKEN environment variable.
Sourcepub fn from_file() -> Result<Self, LinearError>
pub fn from_file() -> Result<Self, LinearError>
Create a client from the ~/.linear_api_token file.
Sourcepub fn auto() -> Result<Self, LinearError>
pub fn auto() -> Result<Self, LinearError>
Create a client by auto-detecting the token (env -> file).
Sourcepub async fn execute<T: DeserializeOwned>(
&self,
query: &str,
variables: Value,
data_path: &str,
) -> Result<T, LinearError>
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.
Sourcepub async fn execute_connection<T: DeserializeOwned>(
&self,
query: &str,
variables: Value,
data_path: &str,
) -> Result<Connection<T>, LinearError>
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.
Sourcepub async fn query<T: DeserializeOwned + GraphQLFields>(
&self,
field: &str,
) -> Result<T, LinearError>
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?;Sourcepub async fn query_connection<T: DeserializeOwned + GraphQLFields>(
&self,
field: &str,
) -> Result<Connection<T>, LinearError>
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
impl Client
Sourcepub fn workflow_states<T>(&self) -> WorkflowStatesQueryBuilder<'_, T>
pub fn workflow_states<T>(&self) -> WorkflowStatesQueryBuilder<'_, T>
All issue workflow states.
Full type: WorkflowState
Sourcepub fn users<T>(&self) -> UsersQueryBuilder<'_, T>
pub fn users<T>(&self) -> UsersQueryBuilder<'_, T>
All users for the organization.
Full type: User
Sourcepub async fn whoami<T: DeserializeOwned + GraphQLFields<FullType = User>>(
&self,
) -> Result<T, LinearError>
pub async fn whoami<T: DeserializeOwned + GraphQLFields<FullType = User>>( &self, ) -> Result<T, LinearError>
The currently authenticated user.
Full type: User
Sourcepub fn projects<T>(&self) -> ProjectsQueryBuilder<'_, T>
pub fn projects<T>(&self) -> ProjectsQueryBuilder<'_, T>
All projects.
Full type: Project
Sourcepub async fn project<T: DeserializeOwned + GraphQLFields<FullType = Project>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn project<T: DeserializeOwned + GraphQLFields<FullType = Project>>( &self, id: String, ) -> Result<T, LinearError>
One specific project.
Full type: Project
Sourcepub fn teams<T>(&self) -> TeamsQueryBuilder<'_, T>
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
Sourcepub async fn team<T: DeserializeOwned + GraphQLFields<FullType = Team>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn team<T: DeserializeOwned + GraphQLFields<FullType = Team>>( &self, id: String, ) -> Result<T, LinearError>
One specific team.
Full type: Team
Sourcepub fn search_issues<T>(
&self,
term: impl Into<String>,
) -> SearchIssuesQueryBuilder<'_, T>
pub fn search_issues<T>( &self, term: impl Into<String>, ) -> SearchIssuesQueryBuilder<'_, T>
Search issues.
Full type: IssueSearchResult
Sourcepub fn issues<T>(&self) -> IssuesQueryBuilder<'_, T>
pub fn issues<T>(&self) -> IssuesQueryBuilder<'_, T>
All issues.
Full type: Issue
Sourcepub async fn issue<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn issue<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, id: String, ) -> Result<T, LinearError>
One specific issue.
Full type: Issue
Sourcepub fn issue_relations<T>(&self) -> IssueRelationsQueryBuilder<'_, T>
pub fn issue_relations<T>(&self) -> IssueRelationsQueryBuilder<'_, T>
All issue relationships.
Full type: IssueRelation
Sourcepub async fn issue_relation<T: DeserializeOwned + GraphQLFields<FullType = IssueRelation>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn issue_relation<T: DeserializeOwned + GraphQLFields<FullType = IssueRelation>>( &self, id: String, ) -> Result<T, LinearError>
One specific issue relation.
Full type: IssueRelation
Sourcepub fn issue_labels<T>(&self) -> IssueLabelsQueryBuilder<'_, T>
pub fn issue_labels<T>(&self) -> IssueLabelsQueryBuilder<'_, T>
All issue labels.
Full type: IssueLabel
Sourcepub fn documents<T>(&self) -> DocumentsQueryBuilder<'_, T>
pub fn documents<T>(&self) -> DocumentsQueryBuilder<'_, T>
All documents in the workspace.
Full type: Document
Sourcepub async fn document<T: DeserializeOwned + GraphQLFields<FullType = Document>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn document<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, id: String, ) -> Result<T, LinearError>
One specific document.
Full type: Document
Sourcepub fn cycles<T>(&self) -> CyclesQueryBuilder<'_, T>
pub fn cycles<T>(&self) -> CyclesQueryBuilder<'_, T>
All cycles.
Full type: Cycle
Sourcepub async fn cycle<T: DeserializeOwned + GraphQLFields<FullType = Cycle>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn cycle<T: DeserializeOwned + GraphQLFields<FullType = Cycle>>( &self, id: String, ) -> Result<T, LinearError>
One specific cycle.
Full type: Cycle
Sourcepub async fn file_upload(
&self,
meta_data: Option<Value>,
make_public: Option<bool>,
size: i64,
content_type: String,
filename: String,
) -> Result<Value, LinearError>
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.
Sourcepub async fn image_upload_from_url(
&self,
url: String,
) -> Result<Value, LinearError>
pub async fn image_upload_from_url( &self, url: String, ) -> Result<Value, LinearError>
Upload an image from an URL to Linear.
Sourcepub async fn issue_create<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
input: IssueCreateInput,
) -> Result<T, LinearError>
pub async fn issue_create<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, input: IssueCreateInput, ) -> Result<T, LinearError>
Creates a new issue.
Full type: Issue
Sourcepub async fn issue_update<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
input: IssueUpdateInput,
id: String,
) -> Result<T, LinearError>
pub async fn issue_update<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, input: IssueUpdateInput, id: String, ) -> Result<T, LinearError>
Updates an issue.
Full type: Issue
Sourcepub async fn issue_archive<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
trash: Option<bool>,
id: String,
) -> Result<T, LinearError>
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
Sourcepub async fn issue_unarchive<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn issue_unarchive<T: DeserializeOwned + GraphQLFields<FullType = Issue>>( &self, id: String, ) -> Result<T, LinearError>
Unarchives an issue.
Full type: Issue
Sourcepub async fn issue_delete<T: DeserializeOwned + GraphQLFields<FullType = Issue>>(
&self,
permanently_delete: Option<bool>,
id: String,
) -> Result<T, LinearError>
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
Sourcepub async fn issue_relation_create<T: DeserializeOwned + GraphQLFields<FullType = IssueRelation>>(
&self,
override_created_at: Option<Value>,
input: IssueRelationCreateInput,
) -> Result<T, LinearError>
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
Sourcepub async fn document_create<T: DeserializeOwned + GraphQLFields<FullType = Document>>(
&self,
input: DocumentCreateInput,
) -> Result<T, LinearError>
pub async fn document_create<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, input: DocumentCreateInput, ) -> Result<T, LinearError>
Creates a new document.
Full type: Document
Sourcepub async fn document_update<T: DeserializeOwned + GraphQLFields<FullType = Document>>(
&self,
input: DocumentUpdateInput,
id: String,
) -> Result<T, LinearError>
pub async fn document_update<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, input: DocumentUpdateInput, id: String, ) -> Result<T, LinearError>
Updates a document.
Full type: Document
Sourcepub async fn document_delete<T: DeserializeOwned + GraphQLFields<FullType = Document>>(
&self,
id: String,
) -> Result<T, LinearError>
pub async fn document_delete<T: DeserializeOwned + GraphQLFields<FullType = Document>>( &self, id: String, ) -> Result<T, LinearError>
Deletes (trashes) a document.
Full type: Document
Sourcepub async fn comment_create<T: DeserializeOwned + GraphQLFields<FullType = Comment>>(
&self,
input: CommentCreateInput,
) -> Result<T, LinearError>
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
impl Client
Sourcepub async fn download_url(
&self,
url: &str,
) -> Result<DownloadResult, LinearError>
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();Sourcepub async fn upload_file(
&self,
filename: &str,
content_type: &str,
bytes: Vec<u8>,
make_public: bool,
) -> Result<UploadResult, LinearError>
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:
- Call the
fileUploadGraphQL mutation to obtain a signed upload URL and required headers from Linear. PUTthe 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— Iftrue, 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);