HOWTO Debug SharePoint 2013 REST Calls in Workflows

I am creating SharePoint 2013 workflows using SharePoint Designer 2013 that makes web service calls to the various SharePoint 2013 REST APIs.

The REST URL format is slightly confusing for new users, so I am documenting how I uncovered various methods here and what you can do to debug REST calls in SharePoint 2013. My principal tool for debugging is the Fiddler web debugging tool.

Creating a Request in Fiddler

I am using the Composer function to create URLs to call REST APIs in SharePoint 2013. This allows me to set the HTTP method (GET, POST, UPDATE, MERGE, etc), the URL, and watch the response from the server.

Testing the URL Path

REST URL requests are very specific in the path for the requrement. Here is an example:

HTTP GET – http://myurl/sites/abc/_api/web/

This REST url returns the properties of the web located at http://myurl/sites/abc/, and also provides a list of the next level objects available to call via the API. You can get the Current User information via the REST api by using:

HTTP GET – http://myurl/sites/abc/_api/web/currentuser

This should return details about the Current User as per the user profile in your SharePoint environment.

Here is another example for the GetFileByServerRelativeUrl:

HTTP GET – http://myurl/sites/abc/_api/web/GetFileByServerRelativeUrl(‘/sites/abc/Library1/my.docx’)

This REST url has a number of different elements.

  1. The site is used to access the web api (_api/web)
  2. The api method (GetFileByServerRelativeUrl) is used to access an SPFile
  3. The server relative url is required for this particular method call

Getting the Context Info

The Context Info is a mechanism for SharePoint to ensure users aren’t tricking into calling SharePoint without their knowledge. You can use Fiddler again to view your context info:

HTTP POST – http://myurl/sites/_api/contextinfo

Your return result will include the context element d:FormDigestValue, and this value can then be passed in via headers to web service calls using the header “X-RequestDigest”.

Common Errors

HTTP/1.1 403 Forbidden

The REST API call may not have the correct X-RequestDigest (see previous Getting the Context Info section). You can view more detail via Fiddler when you click on the “TextView” tab. Look for “The security validation for this page is invalid. Click Back in your web browser, refresh the page, and try your operation again.”

HTTP/1.1 405 Method Not Allowed

The REST API call accepts particular HTTP method(s) (like GET, POST, UPDATE etc). Try changing the HTTP method (eg from GET to POST).

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: