Hello,
It looks like you're encountering a 401 Unauthorized error when calling the DocuSign API with a JWT token. Here are a few steps to troubleshoot and track this issue on your demo account:
-
Verify JWT Configuration: Double-check your JWT token configuration, ensuring that the integration key, private key, and issuer account ID are correctly set up in your code or application.
-
Check API Endpoint and Scope: Ensure that your API call is targeting the correct endpoint (demo.docusign.net
for the demo environment) and includes the necessary scopes for envelope creation (signature
scope is typically required).
-
Token Expiration and Renewal: JWT tokens have a limited validity period. Make sure your token hasn't expired. If it has, regenerate a new token following DocuSign's JWT token generation process.
-
Review DocuSign API Logs: Log in to your DocuSign developer account and check the API logs for any specific error messages or additional details related to the 401 error. This can provide insights into what might be going wrong with your API request.
-
Validate Permissions and Roles: Ensure that the account associated with your JWT token has the necessary permissions to create envelopes. Check roles and permissions settings in your DocuSign account.
-
Contact DocuSign Support: If the issue persists after checking the above steps, reach out to DocuSign support. Provide them with the X-DocuSign-TraceToken from the response headers. This token can help them trace the specific API request and diagnose the issue more effectively.
By following these steps, you should be able to track down and resolve the 401 Unauthorized error when calling the DocuSign API on your demo account.
Hope this helps!
Hello mohithitsuccess,
The "401 Unauthorized" error means that the client request was not completed because it lacks valid authentication credentials for the requested resource. To resolve this issue, please verify your OAuth details and ensure that all your headers are correctly set.
Here is an example of how your headers should be formatted:
Headers = {
 'Accept': 'application/json',
 'Content-Type': 'application/json',
 'X-DocuSign-Authentication': {
  'Username': 'abcusername',
  'Password': 'password123',
  'IntegratorKey': 'xyz123'
 }
};
res = nlapiRequestURL('https://demo.docusign.net/restapi/v2/login_information', '', headers, 'GET');
Please ensure that the 'X-DocuSign-Authentication' object is formatted correctly in your headers. If you have any further questions or need additional assistance, feel free to reach out.
Kind regards,
Leandro Reis | Developer Support Engineer
Docusign
@Leandro.Reis here is my current api call which still return the same error as stated by @mohithitsuccess. what am I doing wrong
```
def get_docusign_client():
  api_client = ApiClient()
  api_client.set_base_path(DOCUSIGN_API_BASE_URL)
Â
  with open(DOCUSIGN_PRIVATE_KEY_FILE, 'rb') as private_key_file:
    private_key_bytes = private_key_file.read()
Â
  try:
    # Request JWT user token
    oauth = api_client.request_jwt_user_token(
      client_id=DOCUSIGN_CLIENT_ID,
      user_id=DOCUSIGN_USER_ID,
      oauth_host_name=DOCUSIGN_AUTH_SERVER,
      private_key_bytes=private_key_bytes,
      expires_in=3600,
      scopes= 'signature', 'impersonation', 'envelope_create', 'envelope_edit']
    )
Â
    # Set the Authorization header
    api_client.set_default_header('Authorization', f"Bearer {oauth.access_token}")
Â
    # Set the X-DocuSign-Authentication header
    auth_header_value = {
      'Username': 'bestusawatches@gmail.com',
      'Password': 'Bestwatchesusa_01',
      'IntegratorKey': DOCUSIGN_CLIENT_ID
    }
    api_client.set_default_header('X-DocuSign-Authentication', json.dumps(auth_header_value))
Â
  except ApiException as e:
    print(f"Error: {e}")
    raise e
Â
  return api_client
```
here is the error for context
```
docusign_esign.client.api_exception.ApiException: (401)
Reason: Unauthorized
Trace-Token: 7a94c9d9-f8fa-4bb3-a408-e2d111006789
Timestamp: Wed, 28 Aug 2024 17:40:05 GMT
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache', 'Content-Length': '125', 'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Origin', 'X-Content-Type-Options': 'nosniff', 'X-DocuSign-TraceToken': '7a94c9d9-f8fa-4bb3-a408-e2d111006789', 'X-DocuSign-Node': 'SE4FE19', 'Date': 'Wed, 28 Aug 2024 17:40:05 GMT'})
HTTP response body: b'{"errorCode":"USER_AUTHENTICATION_FAILED","message":"One or both of Username and Password are invalid. Invalid access token"}'
```