GraphQL API
Overview
Flat's API lets you read and write your organization's data programmatically. You can use it to import data into Flat, generate custom reports, build automations driven by events in other apps, and more.
The API is based on GraphQL. Unlike a REST API, a GraphQL API has just a single endpoint for all requests, both reads and writes, and it gives you full control over the shape of the data you get in response. If you're new to GraphQL, we recommend checking out the official GraphQL documentation to learn the basics.
The API is currently in beta and undergoing rapid development. We don't expect there to be breaking changes, but if there are, we'll keep you in the loop.
Endpoint and schema
Flat's GraphQL API endpoint is:
The endpoint supports GraphQL introspection, so the easiest way to explore the API schema and take it for a spin is via a GraphQL client.
Alternatively, you can view the schema here in SDL format.
Authentication and authorization
You authenticate to the API using a bearer token. Just include the HTTP Authorization
header in all of your API requests:
Currently, the API supports personal access tokens. A personal access token is tied to a particular user. It has access to the same workspaces and topics as the user, and any mutations made using it are attributed to the user.
To request your personal access token, reach out to us through one of our support channels.
Operations
The API supports two kinds of operations: queries and mutations.
Queries
Queries fetch data from your organization and are read-only. The API supports:
Fetching individual objects by ID, e.g., getting a specific topic
Listing whole classes of objects, e.g., all accessible workspaces in your organization
Traversing the relationships between objects, e.g., getting a topic along with its labels, owner, collaborators, etc.
Mutations
Mutations modify data in your organization — for example, creating or updating a topic is a mutation. Every mutation returns a reference to the object that was created or updated. That way, you can retrieve information about the mutated object, such as getting a newly created object's system-generated ID.
Making your first request
Request
To make a request to the API, just issue a POST request with a JSON object as the body, structured like this:
The properties are:
query
: required property that contains a GraphQL document describing one or more operations (queries or mutations)variables
: optional property that contains a mapping of variables and values to substitute into the GraphQL documentoperationName
: optional property with the name of the GraphQL operation to execute (required ifquery
defines more than one operation)
Below is an example JSON body requesting a topic's description and title, using a variable for the topic ID.
Here's an example of a complete request that retrieves info about all accessible topics in your organization.
Response
In GraphQL, the response data is always structured to match the shape of your request.
In the example request above, the response would look like this:
Working with the API
Pagination
For API fields that return a list of objects, the API will return up to 50 objects per request. To get more results, the API supports forward and backward cursor-based pagination following the Relay "Connections" spec. You can learn more about the reasoning behind this approach in the official GraphQL documentation.
Let's say you want to get all of the accessible topics in your organization. You could execute the query below to get the first page of 50 topics.
To get the next page, take the value of pageInfo.endCursor
in the response and pass it as the value of after
in the next request. When pageInfo.hasNextPage
is false in the response, you've retrieved all the results.
If you don't need any of the edge fields, you can simplify the query and jump directly to the nodes like this:
Pagination direction
Lists of objects are returned in order of creation time. The example above would retrieve the oldest topics first. To get the newest objects first, you can paginate backwards instead of forwards using the corresponding arguments and fields:
Pagination direction | Arguments | Fields |
---|---|---|
Forwards |
|
|
Backwards |
|
|
Filtering
Most API fields that return a list of objects support filtering. Here's an example query to retrieve archived topics with the label "bug":
By default, the API only returns "active" entities, e.g., topics that have not been archived or trashed, workspaces that have not been archived, etc. However, most filters have a states
field that lets you override the default and specify which state(s) to include.
Examples
Below are some example GraphQL documents for common use cases.
Keep in mind:
These are example GraphQL documents, not complete API requests. See Making your first request to form a complete API request from a GraphQL document.
In these examples, the values are hard-coded into the GraphQL document for illustration. However, you'll typically want to use variables to parameterize your queries and mutations for easy reuse.
Queries
Fetching info about workspaces and their stages
Fetching info about users
Fetching info about a single topic
Mutations
Creating a topic
Updating a topic's basic details
Updating a topic's owner
Updating a topic's collaborators
Updating a topic's labels
Support
If you have any questions or issues with the API, just reach out to us through one of our support channels.
Last updated