Checking API Logs Like the Weather

A couple weeks ago I was working on a prototype for a new feature, and somehow I kept getting an error from the Docusign API.  The error stubbornly told me that I was providing the wrong content type, even though I was certain that I was explicitly specifying “application/json." I could probably spend a lot longer on this if it wasn’t for a helpful request logging feature, that was actually implemented nearly a year ago.

What’s interesting about request logging is that it’s available to all users, not just developers.  Having wide availability allows your support staff to be able to debug problems with your user’s account, while they maintain full control.  Just ask them to go to My Preferences / Privacy & Security and at the bottom enable “Request Logging."

The error I was getting was:

  "errorCode": "INVALID_CONTENT_TYPE",
  "message": "Content Type specified is not supported.”

Even though I though I was setting the content correctly:

HttpRequest httpRequest = new HttpRequest();
httpRequest.setEndPoint(this.apiUrl + '/accounts/' + account + '/envelopes' );
httpRequest.setMethod('POST');httpRequest.setHeader('X-Docusign-Authentication',  header( email, password));
httpRequest.setHeader('Content', 'application/json');
httpRequest.setHeader('Accept', 'application/json');

The cool thing about request logging in Docusign is that it logged my request body as well as headers.  What I realized is that I mistyped the header and should have specified in:

httpRequest.setHeader('Content-Type', 'application/json');

The default Content from this HTTP library was “application/x-www-form-urlencoded.”  When I saw the logs on the server side and saw both Content-Type and Content, the problem became crystal clear.

Getting the API logs is also available via API!

PUT https://{server}/restapi/{apiVersion}/diagnostics/settings

Accept: application/json
Content-Type: application/json
"apiRequestLogging": "true"

If you are developing an application and having problems, or if your customer is having an issue using your integration, this could be an easy way to get to the root of the problem. Docusign has been using the feature to help hundreds of customers who have had trouble with third party software packages.

More information can be found in API Request Logging.

Related Topics