Skip to main content
Nintex Community Menu Bar

How to execute a SP2013 REST API request with Nintex Workflow

With all the Nintex Workflow actions, we can achieve lots of great workflows. Sometimes, we'd like to build more complicated, technical, reusable workflows. For these workflows, we need more actions and possibilities that can be achieved by calling SharePoint ASMX web services or SP2013 REST API requests.

As the ASMX web services are deprecated in SharePoint 2013 and SharePoint Online, it is recommended to use SP2013 REST API instead when it is possible (not all functionalities of the ASMX web services are available in SP2013 REST API).

I'd like to help you building your SP2013 REST API requests.

There are two categories of SP2013 REST API requests :

  • POST : to update, create or remove information in SharePoint,
  • GET : to retrieve information from SharePoint.

The process to execute these two types of requests is different.

 

How to execute a GET request

 

To execute a GET request, a "Web request" action only is needed. The configuration of the action should look like this :

 

It is possible to select a text variable in the "Store result in" field to get the response of the request and then use a "Query XML" action to extract the information needed.

 

 

How to execute a POST request

 

The execution of a POST request is more complex. A request digest is first needed in order to pass the security information to the server when sending the POST request.

To get the request digest, the following "Web request" action should be executed :

 

A text variable has to be selected in the "Store result in" field.

Then the request digest has to be extracted from the response of the request.

To extract this information, a "Query XML" action has to be configured to execute the following XPath query :

//*/local-name()='FormDigestValue']

 

Once the request digest is stored in a variable, it is possible to execute the POST request via a "Web request" configured like the following :

 

 

 

Example : How to update a list item using REST API

 

Before executing the POST request used to update a list item, the request digest and the list item entity type full name are needed.

To get the request digest, follow the steps explained above.

To get the list item entity type full name, execute the following "Web request" action (where "txtListName" is the title of the list where the list item to update is) :

 

The next step is to extract the list item entity type full name from the response of the above request using the following XPath query :

//*elocal-name()='ListItemEntityTypeFullName']

 

The last step is to execute the POST request with the following "Web request" action (where "numID" is the id of the item to update) :

 

 

I hope that this will help the community !

 

Caroline Jung

Hi Sorav,
I have sane problem as of yours. Can you please share your answer to me like what type of changes you made.


Hi Caroline,

Oh, yes, until this afternoon I had the metadata parameter, and it produced the same error. I removed this afternoon after reading something online, and I thought it would work...but it didn't

Thanks,

Katherine


Can you try with the following XPath query?

//*[local-name()='Employee_x0020_Name']


Hi,
I have tried this but its not working.

I am attaching the screen-shot of the result.

It is giving back XML


Hi,

Is your XML beginning with "Response status code: 200 Response content:" or with "<?xml version="1.0" encoding="utf-8"?><entry xml:base="http://brvm153:45438/sites/devs/tb/_api/""?

It should begin with "<?xml version="1.0" encoding="utf-8"?><entry xml:base="http://brvm153:45438/sites/devs/tb/_api/""

I hope it will work


Hi Katherine,

Can you remove "Accept" header and try again?

Regarding "Content-type" header, is it the header automatically added when you select POST method?


Hi Caroline,

I removed the accept header and received this error message:

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2130575251, Microsoft.SharePoint.SPException</m:code><m:message xml:lang="en-US">The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again.

Yes, the content-type header is automatically added (and required) when you select the POST method. 

*Edit* I have noticed in the response header the first line is: ""Transfer-Encoding=chunked","Cache-Control=private, max-age=0","Content-Type=application/json;odata=verbose;charset=utf-8","Expires=Tue, 30 May 2017 07:04:49 GMT","Last-Modified=Wed, 14 Jun 2017 07:04:49 GMT". Could that first date be causing all these issues?

I was just wondering - is there another way to create a subsite without using the 'create site' action?

Thanks,
Katherine


No my xml starts with <?xml version="1.0" encoding="utf-8"?><entry xml:base="http://brvm153:45438/sites/devs/tb/_api/


Hi Caroline,

I have check my XML start with same string as you say. I doubt it can be environment difference. Mine is SharePoint 2013 on- premise version. Can you please share your environment. If you need more details regarding my environment configuration then I can be reached at my email-id. I would be really happy to get more help.


Hi Katherine,

I think that the error message that you received is due to the request digest. Which url do you use to get the request digest?

I don't know any other way of creating a subsite without the "create site" action, sorry.

There's another url that you can use but it's almost the same that you've used :

{Workflow Context:Current site URL}‍/_api/web/webs/add

With the exact same headers but the following body (you can add the description as well) :

{ 'parameters': { '__metadata':{ 'type': 'SP.WebCreationInformation' }, 'Title':'Created From WF','Url':'createdwf', 'WebTemplate':'STS#0', 'UseSamePermissionsAsParentSite':true } }

Hope this helps


Hi Kunal,

Can you share with me the whole XML you're using to test the XPath query?

You're right, it can't be due to an environment difference and there's no specific configuration that can alter the proper functioning of this action.


Hi Caroline,

I didn't think there was another way...but just in case I thought it better to ask.

Unfortunately, this produces the same error as /web/webinfos/add. Could it be possible that this is an error with Nintex/SharePoint?

Thank you for your time and help


Hi Caroline,

Thanks for your help - it wasn't working within the App Step action. I took it out of the app step, and it now works

Katherine


Hi Katherine,

Thanks a lot for your feedback !

That's good to know

I'm glad that you could finally get your workflow working .

Have a nice day,

Caroline


Caroline,

I was able to build a Nintex Workflow to permanently delete content (bypass recycle bin) using this post as a baseline.

Many thanks to you,

-JC


Hi Joseph,

Thanks for your feedback, I'm really happy that this blog can help !

Have a nice day,

Caroline Jung


Hello,

I am trying to follow your example here, but I am having some difficulties following your variables.  Are the variables listed with txt in front variables or columns?  Along with what does the num_ID have to be in your example?  Just something to differentiate the item?  And is webURL just a variable that contains the URL of the API you are getting info from?

Thank you,

Duncan


WebURL is a common property supplied by the Nintex actions themselves and gives you the current web address.

I would imagine the workflow variables called txt... are single line of text variables and have been named in that way so that you can see quickly what type they are.


You're absolutely right Cassy I have the habit to prefix variable names with something that help me identifying the type of the variable.

WebUrl is the reference that you can find in "Common" tab when adding a reference and correspond to the absolute url of the current web site.

In my example, "numID" is a workflow variable where the list item id of an item is stored.

Don't hesitate if you have other questions



I am trying to remove an external users permissions from a document with a post request

I was able to get the Request Digest, however when I try to do a post request ‌to /_api/SP.Sharing.DocumentSharingManager.UpdateDocumentSharingInfo I get the following error
‌{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Not well formatted JSON stream."}}}

I think the issue is to do with the body, which I have built up into a single variable.
{'resourceAddress':'https://xxx.sharepoint.com/sites/xxx/xxx/xxx.docx','userRoleAssignments':p{'__metadata':{'type':'SP.Sharing.UserRoleAssignment'},'Role':'0','UserId','xxx@xxx.com'}],'validateExistingPermissions':false,'additiveMode':false,'sendServerManagedNotification':false,'customMessage':'','includeAnonymousLinksInNotification':false}

I have tried single quotes, double quotes, escaping the quotes, but I get the following error message.
{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Not well formatted JSON stream."}}}

I have verified that the following does work in javascript
var data = "{""resourceAddress"":""https://xxx.sharepoint.com/sites/xxx/xxx/xxx.docx"


Are you using Nintex for O365 or Nintex for SharePoint Onpremise?


Thanks for your response. It was for Nintex for O365. I re-created a new web request with the same configuration and that seemed to do the trick. There was nothing wrong with the body variable after all. Thanks again


Great, I'm glad that you could find a solution to your problem


Caroline,

Thank you so much for the information.  I was able to use it to create an item in a list on a different site with the Web request action, and then update a column in the new item.  I also need to add any attachments from the original list item to the new item, but haven't found the right combination of URL, headers and json to make it work however.  Any help you could give me would be most appreciated.

I have it working so the file name is attached to the new item, but if you open that attachment, it just shows you a small x, so it doesn't look like the actual file was attached.  By the way, I am doing this cross-domain.

My URL looks like this:

<website>/_api/web/Lists/getByTitle('HotWorkPermitsFromExternal')/items(54)/AttachmentFiles/add(FileName='1503678393715584089584.jpg')

The content type is application/json;odata=verbose

I have Headers of X-RequestDigest with a value of the digest request you explained how to get,

and IF-MATCH with a value of *


I'm glad that this blog has helped you .

Regarding list item attachments, here's the documentation to retrieve list item attachments (one request for the properties such as the file name and one request for the file content using $value) and to add new attachments:

https://dev.office.com/sharepoint/docs/sp-add-ins/working-with-folders-and-files-with-rest#FileAttachments

You could retrieve attached files from one list item and based on information you've retrieved you could create attachments to the other list item.

Hope this helps


Reply