Docusign Integration

anchal1234
Tera Contributor

How to generate access token for docusign using authorization code as grant type 

 

1 REPLY 1

Shaqeel
Mega Sage

Hi @anchal1234 

 

Generating an access token for DocuSign using the authorization code as the grant type involves several steps.

Here's a step-by-step guide:

 

1. First, you need to get the authorization code. This is done by directing the user to the DocuSign OAuth authorization URL. The URL should look something like this: https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature%20impersonation&client_...}. Replace {CLIENT_ID} and {REDIRECT_URI} with your actual client ID and redirect URI.

 

2. The user will be prompted to log in to their DocuSign account and grant your application access. After they do this, they will be redirected to your redirect URI with an authorization code in the query string.

 

3. You can extract this authorization code from the query string. This code is temporary and will expire after a short time.

 

4. Now that you have the authorization code, you can exchange it for an access token. To do this, make a POST request to the DocuSign OAuth token endpoint (https://account-d.docusign.com/oauth/token). The body of the request should be a JSON object with the following properties:

- grant_type: Set this to "authorization_code".

- code: The authorization code you obtained in step 3.

- client_id: Your client ID.

- client_secret: Your client secret.

- redirect_uri: Your redirect URI.

 

5. If the request is successful, the response will be a JSON object containing your access token, refresh token, and other information. You can extract the access token from this response and use it to make authenticated requests to the DocuSign API.

 

Here's a sample code snippet in JavaScript using the axios library to make the POST request:

 

javascript

const axios = require('axios');

const qs = require('querystring');

const requestBody = {

grant_type: 'authorization_code',

code: 'YOUR_AUTHORIZATION_CODE',

client_id: 'YOUR_CLIENT_ID',

client_secret: 'YOUR_CLIENT_SECRET',

redirect_uri: 'YOUR_REDIRECT_URI'

};

 

axios.post('https://account-d.docusign.com/oauth/token', qs.stringify(requestBody), {

headers: {

'Content-Type': 'application/x-www-form-urlencoded'

} }).then(response => {

console.log(response.data.access_token);

}).catch(error => { console.error(error);

});

 

Remember to replace 'YOUR_AUTHORIZATION_CODE', 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', and 'YOUR_REDIRECT_URI' with your actual values.

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel