Get Started
This tutorial walks you through setting up a Node.js project, authenticating with the Legalesign API, and making your first GraphQL request.
Using Cursor, Claude, or another AI coding tool? Connect it to the Legalesign docs for context-aware help as you follow this tutorial.
Prerequisites
Node.js 18 or later is required. Check your version:
node --version
If not installed, go to https://nodejs.org.
Create a project
mkdir legalesign-example
cd legalesign-example
npm init -y
No additional packages are needed — Node.js 18+ includes fetch natively.
Get your credentials
Contact Legalesign support to obtain your Client ID, username, and password. See the authentication guide for details.
Get an access token
Create an index.js file:
const LEGALESIGN_AUTH_ENDPOINT = 'https://cognito-idp.eu-west-2.amazonaws.com';
const CLIENT_ID = '<your-client-id>';
const USERNAME = '<your-username>';
const PASSWORD = '<your-password>';
async function getToken() {
const response = await fetch(LEGALESIGN_AUTH_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSCognitoIdentityProviderService.InitiateAuth'
},
body: JSON.stringify({
AuthFlow: 'USER_PASSWORD_AUTH',
ClientId: CLIENT_ID,
AuthParameters: {
USERNAME,
PASSWORD
}
})
});
const data = await response.json();
if (data.__type) {
throw new Error(`Authentication failed: ${data.message}`);
}
return data.AuthenticationResult.AccessToken;
}
In production, store your credentials in environment variables or a secret manager — never hardcode them.
Test the token
async function main() {
const token = await getToken();
console.log('Token obtained:', token.substring(0, 20) + '...');
}
main().catch(console.error);
node index.js
You should see:
Token obtained: eyJraWQiOiJhYmNkZW...
Make a GraphQL request
Add a helper function and query your user info:
const GRAPHQL_ENDPOINT = 'https://graphql.uk.legalesign.com/graphql';
async function graphql(token, query, variables = {}) {
const response = await fetch(GRAPHQL_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ query, variables })
});
const result = await response.json();
if (result.errors) {
console.error('GraphQL errors:', result.errors);
}
return result;
}
async function main() {
const token = await getToken();
const result = await graphql(token, `
query {
user {
id
firstName
lastName
email
}
}
`);
console.log(JSON.stringify(result, null, 2));
}
main().catch(console.error);
Expected output:
{
"data": {
"user": {
"id": "dXNyNjBkNWNkODktMDg3NS00ZXC67mItZjI3ODA5NjgwMDdl",
"firstName": "Your",
"lastName": "Name",
"email": "<your-email>"
}
}
}