Skip to main content

My User Example

Open the Legalesign GraphQL Explorer​

note

If you don't yet have any legalesign.com credentials, go to the free trial page and sign up here

Create a Query​

In order to get you going as quickly as possible, let's execute a query straight away and make sure that everything is working.

Past the following into the main query window.

query GetUser($id: ID!) {
user(id: $id) {
id
name
email
firstName
lastName
}
}

By default, if you call the user object without an id the information returned is your own.

Running this sample​

This code will create a command line example that accepts a username and password, then returns the result of this query.

auth-example.js
const AWS = require('aws-sdk');
const fetch = require('node-fetch');

class LegalesignAuth {
constructor() {
// General purpose pool credentials
this.userPoolId = '<your_user_pool_id>';
this.clientId = '<your_client_id>';
this.region = 'eu-west-2';

this.cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({
region: this.region
});
}

async getAccessToken(username, password) {
try {
const params = {
AuthFlow: 'USER_PASSWORD_AUTH',
ClientId: this.clientId,
AuthParameters: {
USERNAME: username,
PASSWORD: password
}
};

const result = await this.cognitoIdentityServiceProvider.initiateAuth(params).promise();
return result.AuthenticationResult.AccessToken;
} catch (error) {
throw new Error(`Authentication failed: ${error.message}`);
}
}

async makeGraphQLRequest(token, query) {
const response = await fetch('https://graphql.uk.legalesign.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ query })
});

return response.json();
}
}

// Example usage
async function main() {
const [username, password] = process.argv.slice(2);

if (!username || !password) {
console.error('Usage: node auth-example.js <username> <password>');
process.exit(1);
}

try {
const auth = new LegalesignAuth();

// Get access token
console.log('Getting access token...');
const token = await auth.getAccessToken(username, password);

// Test with a simple query
const query = `
query myInfo {
user {
id
firstName
lastName
email
}
}
`;

console.log('Making GraphQL request...');
const result = await auth.makeGraphQLRequest(token, query);

console.log('User info:', JSON.stringify(result, null, 2));

} catch (error) {
console.error('Error:', error.message);
}
}

if (require.main === module) {
main();
}

module.exports = LegalesignAuth;

Run the example:

node auth-example.js your-username your-password