Skip to main content
Question

Issues using $.Ajax sending a DocuSign REST API

  • November 28, 2025
  • 1 reply
  • 15 views

Forum|alt.badge.img

Not sure if my last question was posted…

As I said before, this is not much information on the JavaScript $.ajax call on the DocuSign REST API.  If there was, not much information on it (or even examples).

I’m am trying to use JavaScript (JQuery) $.ajax call using a DocuSign REST API.  Even though I tested out on Postman successfully, it does not work using $.ajax (i.e. https://account-d.docusign.com/oauth/token) including the header information and the requested body (note the ${???} represent a placement of the actual values - just to be safe):

                    let tkHeader = {
                        'Content-Type': 'application/x-www-for-urlencoded',
                        'Accept': '*/*',
                        'Accept - Encoding': 'gzip,deflate,br',
                        'Connection': 'keep-alive',
                        '
Authorization': `Basic ${basicBase64IntSecKey}`
                    }

                    let tkRequestBody = {
                        '
grant_type': 'authorization_code',
                        '
code': `${authCode}`
                    };

(highlighted black on items above represent require files base on Postman forked from DocuSign REST API)

Where ${basicBase64IntSecKey} is the “IntegratorKey” ”Secret Key” with a colon (:) separating them using the following JavaScript Code:

                    let base64 = btoa(`${integrationKey}:${secretKey}`);
                    let basicBase64IntSecKey = `Basic ${base64}`;

 

The code is base on the following URL

                  https://account-d.docusign.com/oauth/auth?  response_type=code&scope=signature&client_id=${integrationKey}&redirect_uri=https://localhost

 

The only way to get the Authorization Code is to run this URL on a browser directly and copy authorization code back to the ${authCode}.

Here is a typical JavaScript $.ajax code using https://account-d.docusign.com/oauth/token as an example:

                    let returnedAuthCode = 'https://localhost/?code=????';  // result from the code URL above
                    let authCode = returnedAuthCode.substring(returnedAuthCode.indexOf("?code=") + 6); // extracting code

                    let base64 = btoa(`${integrationKey}:${secretKey}`);
                    let basicBase64IntSecKey = `Basic ${base64}`;

                    let tkHeader = {
                        'Content-Type': 'application/x-www-for-urlencoded',
                        'Accept': '*/*',
                        'Accept - Encoding': 'gzip,deflate,br',
                        'Connection': 'keep-alive',
                        'Authorization': `Basic ${basicBase64IntSecKey}`
                    }

                    let tkRequestBody = {
                        'grant_type': 'authorization_code',
                        'code': `${authCode}`
                    };

                    var getAccessTokenUrl = 'https://account-d.docusign.com/oauth/token'

 

And the the $.ajax code:

                    $.ajax({
                        type: 'POST',
                        url: getAccessTokenUrl,
                        header: tkHeader,
                        dataType: 'jsonp',
                        body: JSON.stringify(tkRequestBody),
                        success: (response) => {
                            let iDebug = 0;   
// use this as a break point to see what kind of response recieved back
                        },
                        error: function(xhr, status, error) {
                            let xhrStatus = xhr.status;
                            let xhrState = xhr.state();
                            let xhrError = error.charAt(0).toUpperCase() + error.slice(1);
                            console.error(`POST - ${xhrError} Fetching DocuSign Access Token (${xhrStatus} - ${xhrState})
                                \n      URL: ${getAccessTokenUrl}
                                \n   Header: ${JSON.stringify(tkHeader)}
                                \n Req Body: ${JSON.stringify(tkRequestBody)}
                                \n`);
                            $.equiTrak.onLoadingComplete();
                            return;  // End here...
                        }
                    });

 

The problem is that this $.ajax call get refused (404) or CORS Access-Control-Allow-Origin refuseal and I tried other ways to overcome this.   I even include the following configuration in the web.config under the <system.webServicer>:

      <httpProtocol allowKeepAlive="true">
          <customHeaders>
              <add name="
X-Frame-Options" value="ALLOW-FROM *" />
              <add name="
Access-Control-Allow-Origin" value="*" />
              <add name="
Access-Control-Allow-Headers" value="*" />
              <add name="
Access-Control-Allow-Methods" value="*" />
          </customHeaders>
      </httpProtocol>

 

Sorry about the long explanation but right now I’m at wits end and cannot understand why this is not working or if the $.ajax command cannot be used here.

Best  Regards, Terry

 

1 reply

Forum|alt.badge.img+5

Hi Terry,

You will need to ensure you enable CORS for your integration: https://developers.docusign.com/platform/single-page-applications-cors/enable-disable-cors/

The following guide walks you through the API calls and the scope(s) you need to add: https://developers.docusign.com/platform/single-page-applications-cors/