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 all,

did anybody of you tried to update the metadata of a document in a document library with REST Webservice in a Nintex Workflow?

I did create a workflow and it works fine with the syntax of the article above - except for the managed metadata column. This column is always ignored by the web service. Is there any other Syntax compared to a list item??


Hi Christof,

To update a managed metadata field, the body of your request should look like this :

{

     '__metadata': {'type':'yourListItemEntityTypeFullName'},

     'yourManagedMetadataColumnName': {

          '__metadata': {'type':'SP.Taxonomy.TaxonomyFieldValue'},

          'Label':'YourTermLabel',

          'TermGuid':'YourTermGuid',

          'WssId':id

     }

}

As far as I know, updating a multiple managed metadata field using SP2013 REST API is currently not supported. I use the "Update multiple items" action in Nintex Workflow using the following field value:

FirstTermId;#FirstTermLabel|FirstTermGuid;#SecondTermId;#SecondTermLabel|SecondTermGuid

Hope this helps


Hi Caroline,

thanks for your post.

I use exactly the syntax you posted. But on my environment it only works for list items, not for documents in a document library. Do you have other experiences? Does this syntax works for documents on your System?

Best regards

Christof


You can try by adding "ListItemAllFields" to your URL, for example:

http://your_sp_site/_api/web/GetFileByServerRelativeUrl('/your_relative_file_url')/ListItemAllFields

It's explained in this post: Sharepoint Rest API, c#, update document metadata - SharePoint Stack Exchange

Hope this helps


hi Need help create global navigation in SharePoint on prime using nintex workflow + Rest api

The 'Accept' header must be modified using the appropriate property or method.

Parameter name: name

I am getting this error


You can try to execute your web request without the "Accept" header that you've added.

Hope this helps


Yes its working thanks your help .


Does this work in Nintex Workflow online?


Yes it works in Nintex Workflow online. I've just noticed that building Json request body (when performing POST requests) is a bit tricky. I've explained a workaround here :

https://community.nintex.com/message/34252?commentID=34252#comment-34390

Hope this helps


Hi Caroline,

thank you very much for this great article about how to execute a SP2013 REST API request with Nintex Workflow.

I tried to execute your post request code. However the workflow throws an System.UnauthorizedAccessException in the first action by trying to get the contextinfo. In the SharePoint Environment we use ADFS and premise (SharePoint Enterprise2016). I used the normal login credentials (active Directory) for authentication. The user has site collection administrator permission on the site where the list workflow executes.

Fehler beim Ausführen der Webanforderung. <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024891, System.UnauthorizedAccessException</m:code><m:message xml:lang="de-DE">Z

Maybe you can give me a hint.

Thank you and kind regards

Andy


Andy,

Good Morning! I am not sure the settings in SP2016. Did you have any thing in Site features called "Workflow Can use App Permissions". if it is, Try activating that feature. Looks like the workflow is not able to read due to insufficient permissions.

Thanks,

Vinay.


Hi Andreas,

To get the complete error message, you can send you an email in Plain text mode with the error message which you can store in a variable in Error Handling section of the Web request action. You can also test your web request in Nintex Workflow editor, when configuring the web request action, you can click on "Run now" button in the ribbon. It will simulate the execution of the web request.

Can you then share the complete error message you get?

Have a nice day


Hi Caroline,

Does this work for creating a document set automatically from a list item? I've been trying to figure out how to get this to happen and it kind of sounds like I would use a REST API to accomplish it but I'm not quite sure how.


Hi Caroline,

I'm hoping you can help me out - I'm trying to use a web request action in 365 to create a subsite, I have provided the X-RequestDigest value, but am still receiving the The security validation for this page is invalid and might be corrupted error. Is there something else I need to do (other than to give the workflow app full permission) that can resolve this issue?

Secondly, how did you manage to enter content straight into the web request action? Anytime I do that, the workflow suspends with 'Request body cannot be empty'. 

 

Thanks,
Katherine 


Hi Katherine,

Regarding the security issue, can you send to yourself via the workflow the value of the request digest that you provide in the query?

There's nothing else to perform regarding security.

In O365, it's a bit tricky to be able to build the body of the web request. I've described in this discussion how to do it:

https://community.nintex.com/message/34286#comment-34390

Hope this helps


Hi Terek,

I haven't tried to, but it seems possible using listdata.svc:

https://sharepoint.stackexchange.com/questions/114882/is-it-possible-to-create-a-document-set-using-rest-api

It should be possible to perform the query from a workflow using the web request.

Tell me if you managed to create a document set with the web request action.


Hi Caroline,

I've got the workflow logging the request digest value, and emailing me the authenticated header (content type, accept and request digest) in an email. Although, I thought if I used web request and provided an email and password it would create the authentication for the header?

I've just run a test without the username and password and received an 'access denied' message. I have however, managed to add the body of the request straight into the action which makes it a little easier to see what's going on. 

Thanks for your help


Hello,

I have a list that has a field called "codroject".
When this field is filled the workflow should update the commitemnets field of one other list in another site
.

I need create web request to do this.

Who do this?


Hi Katherine,

Great that you managed to build the body . Regarding authentication, did you finally make it working?

Is the request digest value in the correct format?

The request to perform to get the request digest has to be a POST one and not GET.

I maybe forgot to mention that usename and password are mandatory otherwise the web request won't work.

Have a nice day,

Caroline


Hi Jose,

You can follow the example written in this blog post to update a list item.

Tell me if you have issues or problems.

Hope this helps


Hi Caroline,

I still can't get it to work - I've got the request digest as part of the header for the web request, the request digest is in the same format I used during testing for site creation using Postman. The workflow app has elevated permissions and the web request action is in an app step. There's a username and password added to the action. 

Is there anything else for authentication that I need to include? Would it be better to run this using the call http web service action?


Hi Katherine,

Can you send me the url that you've populated in the web request, the headers you've added and the body?

Then it will be easier for me to give you advices.

If you're using SharePoint REST API, then http web service action won't work.


Hi Caroline,

The web request: https://<tenant>.sharepoint.com/sites/<sitecollection>/_api/web/webinfos/add

Method: Post

Header:

Content-Type: application/json;odata=verbose

Accept: application/json;odata=verbose

X-RequestDigest: (calculated by the workflow) e.g.: 0x7B2DCD41DA731F0B58ED0CE2F7677469F897E46A31E386319C49C812AD3E19B1D96CD6500C71F9BF3487706DDBE26C8605E7679285681FC90E97BF0F0A78D871,13 Jun 2017 06:43:02 -0000

Body:

{"parameters": "Url": "choc","Title":"choc - Chocolate","Description": "created by workflow","Language": 1033,"WebTemplate": "STS#0","UseUniquePermissions": true}}

 

Thanks for your help - I'm way out of ideas


Hi Katherine,

There are few things missing in the body.

Can you try with the following body (I've underlined missing caracters)?

{"parameters": { '__metadata': {'type': 'SP.WebInfoCreationInformation' },"Url": "choc","Title":"choc - Chocolate","Description": "created by workflow","Language": 1033,"WebTemplate": "STS#0","UseUniquePermissions": true}}

I hope it will work


Hey Caroline,

I have followed the same steps as you mentioned here for GET request. I got the XML response from web request as below:

Response status code: 200

Response content:
<?xml version="1.0" encoding="utf-8"?><entry xml:base="http://brvm153:45438/sites/devs/tb/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag="&quot;2&quot;"><id>d8d7b397-ba4c-48ac-8e1e-474c4fcb3a8b</id><category term="SP.Data.UserList2ListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/FirstUniqueAncestorSecurableObject" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/RoleAssignments" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/AttachmentFiles" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/ContentType" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/FieldValuesAsHtml" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/FieldValuesAsText" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/FieldValuesForEdit" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/File" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder" type="application/atom+xml;type=entry" title="Folder" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/Folder" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList" type="application/atom+xml;type=entry" title="ParentList" href="Web/Lists(guid'1ba7f9ac-9097-438d-b079-9677419b0917')/Items(9)/ParentList" /><title /><updated>2017-06-13T12:08:59Z</updated><author><name /></author><content type="application/xml"><m:properties><d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType><d:Id m:type="Edm.Int32">9</d:Id><d:ContentTypeId>0x010046DB9F9D7073D346A45596CDAB523B8A</d:ContentTypeId><d:Title m:null="true" /><d:EventsId m:type="Edm.Int32">6</d:EventsId><d:Employee_x0020_Name>Raj</d:Employee_x0020_Name><d:Employee_x0020_Email>raj@vol.com</d:Employee_x0020_Email><d:No_x002e__x0020_of_x0020_Guests m:type="Edm.Double">567</d:No_x002e__x0020_of_x0020_Guests><d:Dietary_x0020_restrictions>&lt;div class="ExternalClass19FEE4156E8A451EB9E052C78EB40793"&gt;&lt;p&gt;non-vol&lt;/p&gt;&lt;/div&gt;</d:Dietary_x0020_restrictions><d:Volunteer_x0020_Events>&lt;div class="ExternalClass8DC76AA6EC7643928AEE26A459CD4143"&gt;&lt;p&gt;Guj&lt;/p&gt;&lt;/div&gt;</d:Volunteer_x0020_Events><d:T_x002d_shirt_x0020_Size m:type="Edm.Double">20</d:T_x002d_shirt_x0020_Size><d:Business_x0020_Unit>3</d:Business_x0020_Unit><d:No_x002e__x0020_of_x0020_tickets m:type="Edm.Double">56</d:No_x002e__x0020_of_x0020_tickets><d:Volunter_x0020_EvntsId m:type="Edm.Int32">2</d:Volunter_x0020_EvntsId><d:DeleteEv m:null="true" /><d:Archivin m:null="true" /><d:OData__dlc_ExpireDate m:type="Edm.DateTime">2017-03-21T11:10:03Z</d:OData__dlc_ExpireDate><d:Test m:type="Edm.DateTime">2017-03-18T18:30:00Z</d:Test><d:SharePoi m:type="Edm.Int32">5</d:SharePoi><d:ID m:type="Edm.Int32">9</d:ID><d:Modified m:type="Edm.DateTime">2017-03-20T10:44:44Z</d:Modified><d:Created m:type="Edm.DateTime">2017-03-20T10:44:44Z</d:Created><d:AuthorId m:type="Edm.Int32">1</d:AuthorId><d:EditorId m:type="Edm.Int32">1</d:EditorId><d:OData__UIVersionString>1.0</d:OData__UIVersionString><d:Attachments m:type="Edm.Boolean">false</d:Attachments><d:GUID m:type="Edm.Guid">0174edce-3aa7-445c-a5b9-1845aaa58068</d:GUID></m:properties></content></entry>

When I use this XML in Query XML action I am getting XPATH as :
/defaultNS:entry/defaultNS:content/defaultNSⓂproperties/defaultNS:d:Employee_x0020_Name

The problem is this is not working as expected (as shown in scree-shot in blog). It does not return me the name of the employee but returns me same XML.

Kindly guide me where I am going wrong.

I am using SharePoint on-premises


Reply