Skip to main content

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

Thank you , there was a syntax error


I'm glad that you could solve your issue


This is a fantastic article and should be bookmarked in every SharePoint developer's Nintex Community profile. Thanks for the guidance, Caroline!


Thanks for the comment Christian ! I'm glad if this article can help


Dear Caroline Jung‌, I need your help.

I 'm using REST API to add permission to a user on an item within a list. I have successfully removed the inheritance with a post request to :

https://URL/ts/_api/web/lists/getByTitle('Timesheet Reports')/items(32)/breakroleinheritance(copyRoleAssignments=true,clearSubscopes=true)‍

However, when I try to add new item level permission to the item with the bellow context:

https://URL/_api/web/lists/getByTitle('Timesheet Reports')/items(32)/roleassignments/addroleassignment(principalid=9;roledefid=1073741826)

‍‍

where principalid=9 is the "ID" for the user (not group) retrieved from :

https://URL/_api/web/siteusers

 

I'll get the bellow error in response :

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>
-1, Microsoft.SharePoint.Client.InvalidClientQueryException
</m:code>
<m:message xml:lang="en-US">
The expression "web/lists/getByTitle('Timesheet Reports')/items(32)/roleassignments/addroleassignment(principalid=9;roledefid=1073741826)" is not valid.
</m:message>
</m:error>‍‍‍‍‍‍‍‍‍

Please advice.

Updates >>

Issue was related to bad syntax. I was using ; instead of ,


I'm using PowerShell to get the list of items that haven't been modified in a while and emailing the last modifier asking them if they want to delete stale items. (We're doing a massive SharePoint cleanup project)

I would like a workflow to delete the item using the web request POST action but am troubleshooting atm.

Is it normal to have the date/time stamp on then end of my Digest Value?

Thanks

Kassie


Dear Kassie,

Digest value always ends with a time stamp, and the timestam is usually half an hour valid.

Your problem should be somewhere else.


Ok, thanks to this post, I've got the auto delete working with the web request for our SharePoint cleanup project.

Now I need to move items to an archive library if the user selects to send the document to records. Is there a method I could use to move a document to the archive list? I would use the copy action but these items are all housed in different library locations on the site collection, they are just listed on this clean up list.  

Any ideas for me?

Thanks

Kassie


Dear Kassie McCool‌, if you mean the list in which it's items should cleaned up, contains document address, then you could simply read the address in workflow (with a variable) and use it in the copy action to copy it to the archive library. then simply delete the document from the original library.

then your workflow should have this actions in order:  ( I couldn't take snapshots so I just type the logic  )

Run If (condition should be "if the user selected the archive option")

Set Variable (read the address in a variable)

Copy Item (Copy the item with the address in variable as source to archive destination library)

Delete Item (use variable as source to delete the Source Item)

}


Thanks for the reply behy.

I'm on 2013 on prem. Not sure if we're on different versions, but my Copy item action does not allow me to customize the source value with a variable value.

Or are you saying to use these methods in my web call?

Thanks

Kassie


You're right Kassie McCool‌, variable is not an option. also you're not able to copy/paste items across sites. you're only able to do that within the same site.

is it in the same site? I mean source and target.


They are on the same site. I was kind of hoping to do this as a web request. I found some info on SharePoint folder moves but I don't want to move a folder, just a document.

Here's what I have so far. I popped off the folder portion of the syntax but it isn't working yet.

https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee658974(v=office.14

I'm sure I'll get there. Just have to keep working on it.

thanks

Kassie


I don't know if it will help in your case, but here is what I have used to move a document within the same library:


Thanks for the reply Ken.

This is getting me pretty close. I found almost the same solution from Vadim Tabakman‌'s blog post here and added a header as he suggested.

I am still having trouble getting it to work. I'm getting an error in my result, "Error performing web request. The underlying connection was closed: The connection was closed unexpectedly." After reviewing the error logs, I found this error: "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

I'm not the admin for our server so I have little troubleshooting ability from that side.

If there's any advice you could give on how to get this up and running I would appreciate it.

Thank you

Kassie

 


Hi Caroline,



I want to update a date field. I copied and changed a working web request to update users in the same workflow.
The result is a 400 Http status.
Do you have any idea what I am doing wrong?
Here is a log extract:



Message body: {'__metadata':{'type':'SP.Data.Dokumente_x0020_TR_x0020_HFItem'},'wf_TR_DBearbeiterStart':{'results':[2019-06-07T00:00:00Z]}}



varDBearbeiterStartResult: 400



 



Best regards Micha


Solution: {'__metadata':{'type':'SP.Data.Dokumente_x0020_TR_x0020_HFItem'},'wf_TR_DBearbeiterStart':'2019-06-11T00:00:00Z'}


Reply