Skip to main content

GraphQL API

Most of the Liveforce API is built using GraphQL, a powerful query language for APIs that allows you to request only the data you need. This section provides an overview of all available GraphQL queries and mutations, along with explanations and examples.

Endpoint​

All GraphQL requests should be made to the following endpoint:

https://api.liveforce.co/gql

Schema​

The entire schema can be downloaded here. You can also use the following link to import the schema into your GraphQL client:

https://docs.liveforce.co/generated/liveforce-api-schema.graphql

Usage​

Here's an example of a request to GraphQL API using Apollo Client, a popular GraphQL client for JavaScript and TypeScript.

index.js
import { ApolloClient, InMemoryCache, gql, HttpLink } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";

const accessToken = "your_access_token_here";

const httpLink = new HttpLink({
uri: "https://api.liveforce.co/0.2/gql",
});

const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
Authorization: `Bearer ${accessToken}`,
},
};
});

const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});

async function main() {
const { data } = await client.query({
query: gql`
query GetUpdatedCrew($time: Time!) {
companyCrewAll(input: { filter: { updatedAfter: $time } }) {
paginatedList {
crewId
firstName
lastName
email
}
}
}
`,
variables: { time: "2020-11-18T12:21:14Z" },
});

console.log("Retrieved", data.companyCrewAll.paginatedList.length, "crew members");
}

main();