KB-1045 "Unable to retrieve RequestDigest to execute POST request" error thrown when using a!shpCopyDocumentFromAppian

Symptoms

When using the SharePoint connector function a!shpCopyDocumentFromAppian to upload a document from Appian to SharePoint, the following is printed in the application server log:

07:38:02,450 INFO  [stdout] (http-/0.0.0.0:8180-4) 2015-07-02 07:38:02,450 [http-/0.0.0.0:8180-4] ERROR com.appiancorp.core.expr.DelayedWriteContext - An error occurred while attempting to store into variable local!shpCopyDocumentFromAppianWriter.  Details: The external server for this system [key=sharepoint] generated an exception when calling a function [shpCopyDocumentFromAppian]. Details from external system: java.lang.RuntimeException: Unable to retrieve RequestDigest to execute POST request

In Appian 7.8 and earlier, this error is shown in the GUI. Starting in 7.9, no error is shown in the GUI but the error is still printed in the application server log.

Cause

The a!shpCopyDocumentFromAppian function uses the POST method to send a file to SharePoint. In SharePoint 2013 a valid digest is required to use POST. In the implementation of the SharePoint Connector functions, the digest is generated by the following lines:

    HttpPost httppostDigest = new HttpPost("/_api/contextinfo");
    httppostDigest.addHeader(new BasicHeader(SharepointHeaders.ACCEPT_JSON.getName(), SharepointHeaders.ACCEPT_JSON.getField()));
    response = executeHttpRequest(targetHost, httpclient, localContext, connection.getRetries(), httppostDigest, "POST");

This seems to cause the upload to fail since there is no SharePoint site configured at the top level (e.g., http://mysharepointserver/). When the above code looks for the context information at an address like http://mysharepointserver/_api/contextinfo, it will fail, generating the Unable to retrieve RequestDigest error.

To confirm there is no top level site, see if there is an error when trying to access http://mysharepointserver/.

Action

Create a top-level site on the SharePoint server so that the context request is successful.

Affected Versions

This article applies to all versions of Appian using SharePoint 2013.

Last Reviewed: February 2016

Related
Recommended