Make a Query
Now that you have the getToken and graphql helper functions from the previous step, let's explore querying the API.
Query with variables
Most queries need an ID. Use GraphQL variables to pass them:
const result = await graphql(token, `
query GetGroup($id: ID!) {
group(id: $id) {
id
name
credit
}
}
`, { id: '<your-group-id>' });
Find your group ID
You can discover your groups by querying your user's memberships:
async function main() {
const token = await getToken();
const result = await graphql(token, `
query {
user {
memberConnection(first: 10) {
members {
group {
id
name
}
}
}
}
}
`);
console.log(JSON.stringify(result, null, 2));
}
main().catch(console.error);
This returns all groups your API user belongs to. You'll need a group ID for most operations — sending documents, listing templates, managing contacts.
Find template role IDs
When sending a document, you need the roleId from the template. Query a template's roles:
const templates = await graphql(token, `
query GetTemplates($groupId: ID!) {
group(id: $groupId) {
templateConnection(first: 5) {
templates {
id
title
roles {
id
signerIndex
}
}
}
}
}
`, { groupId: '<your-group-id>' });
console.log(JSON.stringify(templates, null, 2));
Each role's id is what you pass as both id and roleId in the recipient when sending a document.
Test queries interactively in the GraphiQL Explorer before writing code. See the complex query examples for more nested query patterns.
Using a GraphQL client library
The fetch approach works well for most integrations. If you're building something more complex, consider a dedicated GraphQL client:
- graphql-request — lightweight, promise-based
- Apollo Client — full-featured, with caching and React integration
- Axios — general HTTP client, works fine for GraphQL
See the libraries page for more details.