Skip to main content
Question

Failed to generate a Token : Error while requesting server, received a non successful HTTP code with response Body

  • February 12, 2025
  • 3 replies
  • 110 views

Forum|alt.badge.img

When fetching envelope details based on filters using ListStatusChanges, the request contains customField as the account number and folderIds as sentitems, with include = "custom_fields" (to retrieve other custom field values).

Before executing this request, we call the token API, but the token creation sometimes returns a non-successful HTTP code, though not all the time.

What could be the issue? We are implementing it as mentioned below.

var _apiClient = new ApiClient(_baseurl);
token = _apiClient.RequestJWTUserToken(_integratorKey, _userID, _baseurl, Encoding.UTF8.GetBytes(PrivateKey), 1, Scopes);
TokenGeneratedAt = DateTime.Now;

3 replies

Forum|alt.badge.img+3
  • Docusign Employee
  • 21 replies
  • February 13, 2025

I've reviewed the information provided, and if I understand correctly, the issue is that you're attempting to authenticate with DocuSign but are receiving an unhelpful error message that simply states: "Error while requesting server, received a non-successful HTTP code with response Body: ".

Typically, this type of error would include more specific details. For example, it might say: "Error while requesting server, received a non-successful HTTP code with response Body: {"error":"consent_required"}". In your case, it seems that the actual error message is missing. This is something I’ve seen before, and it often points to some form of network issue.

The problem could potentially be related to a handshake failure with the authentication server. Based on previous cases, here are a few things to check:

a) Ensure that you're passing the correct authServer (aud) value. If you're connecting to a developer account, use: https://account-d.docusign.com. If connecting to a production account, use: account.docusign.com.
b) Verify that the server is using TLS 1.2.
c) Check if you're behind a proxy or firewall, as this can sometimes cause issues.

If you’ve verified the above and are still experiencing the issue, could you provide the exact request using a network trace tool like Fiddler or Wireshark?

Also, could you provide some background on how your code is running? For example, are you using a virtual machine, or is your code running behind a custom-built network with potential restrictions?

Please ensure your request follows this format.
{
  "iss": "<your_integration_key>",
  "sub": "<your_user_ID>",
  "aud": "account-d.docusign.com",
  "iat": <current_unix_epoch_time>,
  "exp": <current_unix_epoch_time+6000>,
  "scope": "signature impersonation"
}

Best,

Dev/API team


Forum|alt.badge.img
  • Newcomer
  • 1 reply
  • March 3, 2025

Hi!

I’ve the same error.

I’m trying to get a JWT in a C# Console app (no web) for sending enveloppes.

But when calling RequestJWTUserToken I have this response :

Error while requesting server, received a non successful HTTP code with response Body: {"error":"consent_required"}

 

I call with these datas :

docuSignClient.RequestJWTUserToken(
                clientId,
                impersonatedUserId,
                authServer,
                privateKeyBytes,
                1,
                scopes)

with :

var scopes = new List<string>
    {
        "signature",
        "impersonation",
    };

authServer = “account-d.docusign.com”

clientId = integration app ID

impersonatedUserId = User ID

and privateKeyBytes = Encoding.UTF8.GetBytes(Config.RSA_PrivateKey.ToCharArray())

 

Any idea about my problem ?


Forum|alt.badge.img+1
  • Newcomer
  • 2 replies
  • March 7, 2025

@DenisC your problem relies in the fact that in order to communicate with DocuSign you need the user to allow DocuSign to do this on its behalf→ hence, you need to redict the user from your webpage to allowing consent on Docusign and then redirect the user back to your web page.

 

function redirectToConsentUrl($clientId, $redirectUri, $scope) {

    $consentUrl = "https://account-d.docusign.com/oauth/auth?response_type=code&scope=$scope&client_id=$clientId&redirect_uri=$redirectUri";

    header('Location: '.$consentUrl);

    //echo "Please visit this URL to authorize the application: $consentUrl";

    exit;

}