On the other hand Sharepoint 2013 comes with a new REST interface that enables us to access and use its resources.When we combine these two new features we get powerful new ways for using our SharePoint workflows.
In this post I will show you how you can use this new action to POST new data to your SharePoint site.
I have created a SharePoint list named WorkflowItems to use for example. We will create items in this list from a workflow using SharePoint REST services. To keep it simple I will leave it with only one column (Title).
Now we can open our SharePoint Designer and create a new site workflow and call it WorkflowItemWizard.
In our new workflow first we will create couple of dictionaries. Dictionary is a new variable type in SharePoint workflows that is used for defining collections of key/pair values and is very important for the Call HTTP service action.
To create a dictionary add Build Dictionary action to you workflow. Using that action specify two new keys Accept and Content-Type and set the values for both of them to application/json; odata=verbose like in the image below
Set the output to a dictionary with a more meaningful name, call it "header". This dictionary will be used as a header for our request.
Next create another dictionary that you will call metadata and in it add a key called type with value SP.Data.WorkflowItemsListItem.
And finally you will need one more dictionary that will contain your request data. Call it parameters, add key __metadata and set its value to the previously created dictionary metadata
Now you are ready to call the web service. Insert action Call HTTP service.
The URL you will require will look like this:
https://<site>/<web>/_api/web/lists/getbytitle('WorkflowItems')/items
and the HTTP method is POST.
Set the request to your parameters dictionary. To set the header of your request go to :
right click on the Call HTTP service -> properties -> RequestHeaders and set it to your header dictionary.
Now you can deploy your workflow and run it. Once it is over you should have a new item created in your list.
From this example you can continue building your solutions, you can add more fields, or use other available REST services for updating list items or deleting them.
One of the biggest advantages using this method to create or update list items is it is not limited to the site in which you workflow runs. Using REST services you can now access and create items in lists on other sites.
If you want to know more about SharePoint 2013 REST you should check this out :
Programming using the SharePoint 2013 REST service
Also check this excellent post on getting data into your workflow from SharePoint using Rest services:
Calling the SharePoint 2013 Rest API from a SharePoint Designer Workflow
It is a really useful informatuion, I will share it with all my colleagues. Thank you for posting it. This is one of the best explanation on using Sharepoint I have ever read. Well done!
ReplyDeletesharepoint digital signature
How do i create item if it contains lookup column ?
ReplyDeleteHello Pradeep,
ReplyDeleteThis is how I was able to create an item with a lookup column. I have expanded my example list with a lookup column and named it "LookupColumn" :). When you are using REST service it will use the ID of the item in the lookup column and because of that it will have a property that in my case looks like "LookupColumnId" (notice the Id part). This property is of "Int32 type". So in the dictionary where you are setting your item properties you should add another key that looks like "YourColumnNameId", set its type to Int32, and the value to match an item id in the lookup list. Hope I was clear.
This comment has been removed by the author.
ReplyDeleteGood day. Can anybody ask me to - how do that method to create list item in other site level.
ReplyDeleteExample, Site 1: http://site1, Site 2: http://site1/sites/site2. How to create copy of list item from site 1 to site 2 list?
I write correct api address and SPList name - but Item don't create. Why so and how to correct it?
Hi,
DeleteBorislav thanks for the post!
Ceprem,
Have you ever found out how to make it work.
The workflow runs with no errors, but no item gets created in the other list.
Thanks,
Laura
I Have the exact same issue. Workflow runs without errors, but nothing is created in the target list (I'm on SharePoint Online, Office 365). Any updates on how to get it to work in SharePoint Online is appreciated!
DeleteSame issue. no new list item. What's gone wrong?
Deletetry to debug using log and check the variable values
DeleteHello thanks for the great information. Now that I got the workflow to "create new items" I am wondering what it would take for the workflow/web service to "update existing" items.
ReplyDeleteHi, my workflow it's attached with SharePoint Online 2013 document library. My library it's configured with document management options: versions, checkout-in, etc. Then i to configure in my SPD 2013 WorkFlow a REST service call with the apropiate action, similar to this: https://domain/sites/sitecollection/subsite/_api/web/GetFileByServerRelativeUrl('/sites/sitecollection/subsite/mylibary/[%Current Item:Nombre%].[%Current Item:Tipo de archivo%]')/CheckIn(comment='Comment',checkintype=1) The MSDN magazine say that calling this service we can approve the document with a major version. But this call response with UNAUTHORIZED, please help. http://msdn.microsoft.com/en-us/magazine/dn198245.aspx I have my SPD 2013 Request Header dictionary configured.
ReplyDeleteThanks very much for this great article;this is the stuff that keeps me going through out these day. Kelly Services Login
ReplyDeleteI'm trying to create a list item in different site collection, getting Unauthorized Exception, I'm the site collection admin on both sites, using SP online.
ReplyDeleteDid you get a solution to this? I am running into the same problem.
Deletetry allowing workflows to run with app permissions (site feature), then add the id of the workflow with permissions. i.e. how its done here:
Deletehttps://rogereriksen.wordpress.com/2013/05/24/create-a-sharepoint-site-using-rest-in-workflow-with-sharepoint-designer/
This comment has been removed by the author.
DeleteDid you get a solution to this?
DeleteHi Sekar,
DeleteHow did you resolve your Unauthorized Exception?
We have been trying to create a Project Server workflow with SPD2013 that creates new list items on the project site, but like Сергей Оленин and sekhar reddy we encounter 'unauthorized' if we use the App Step and without the App Step the workflow seems to run, but no new item is created. Can you help with this? Thanks!
ReplyDeleteHello, I'm curious if you succeeded with inserting rows into another site? If you did, would you mind sharing how you did it? Thanks much
DeleteIn your request header dictionary, add a field called Authorization with no value (leave it blank). Do not forget to insert your call http service into an App Step.
DeleteGood luck.
Hi hesterblok,
DeleteI am curious to know hoe did you manage to resolve 'unauthorized' exception.
I tried what Tiago mentioned about adding empty "Authorization" but it not help. We get a "Forbidden: error doing that.
Hello,
ReplyDeleteI am getting Bad Request error while posting to a share point online list from the designer workflow
Thanks to you! Really helped understand the Call HTTP Web Service Action. Good clarity in the article.
ReplyDeleteThanks to you! Really helped understand the Call HTTP Web Service Action. Good clarity in the article.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis is a very helpful and informative post! Could you please tell me what I would need to do to modify your example to insert a row into a list on another site collection? Both site collections are Office 365 / SharePoint 2013 cloud sites. Thanks much for any help you can provide!!
ReplyDeleteHi.
ReplyDeleteI'm trying to create an item in another list found on another site.
1, In your fourth image, it shows that you have used the variable requestData as your request content. Where is it created/used previously?
2. Is it possible to create a list item in another list found on another site?
You explained very well manner and easy to understand ..Keep it up
ReplyDeleteSharePoint Training Online
Thanks a lot ! so helpful
ReplyDeleteThe given information in this article is very informative
ReplyDeletesharepoint 2013 administration certification
This comment has been removed by the author.
ReplyDeleteVery nice. This article helped me a lot, but just like many others I was looking to add items on other sites, and I had just the same issues as described earliner. Problem was solved by using elevated permissions. Link to solution: https://msdn.microsoft.com/en-us/library/office/jj822159.aspx
ReplyDeleteGreat Article, any hints on how to use this to create a folder in a library in another site?
ReplyDeleteThis comment has been removed by the author.
ReplyDeletewow!! No Comments !just want to say its really very helpful and information for share point user.
ReplyDeleteSharePoint Tutorial
Thanks
How does the requestData should looks like? Is it dictionary with the coulmn name and value?
ReplyDeleteVery good article on setting up!! I hit one snag though, anyone know what this error may be:
ReplyDelete{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Found a node of type 'PrimitiveValue' when starting to read the property value; however, a node of type 'StartObject' was expected. The '__metadata' property must have an object value."}}}
I have deleted and recreated the workflow multiple times and double checked my entries and this error keeps coming up. Thanks so much again for the walkthrough!
Thanks for the article, i'm trying to insert row in a different list based on status change in current list. But I'm receiving "Bad-request" as response. What am i doing wrong here. Anyone who tried this,can share it here?
ReplyDeleteSame issue as Sharepoint Madness the ResponseStatusCode send me a BadRequest thet drives me crazy
ReplyDeleteI was looking to add items on other sites,
ReplyDeletegclub online
goldenslot
สูตรบาคาร่า
Hi Borislav,
ReplyDeleteI am tying to create a list item in a list that exists in a subsite of the site that the workflow is running on.
eg.
-parent site and original list where workflow is kicked off-
https://.sharepoint.com/Lists/Suppliers/
-site that I want to create list item in-
https://.sharepoint.com//Lists/Suppliers/
when i Create an item in the parent site I want to create an item in the child site list.
I have logged after the creation of each dictonary and the variable "header" is returning " header = {"Accept":"application\/json; odata=verbose","Content-Type":"application\/json; odata=verbose"}" for the values of "Accept" and "Content-Type" I entered "application/json; odata=verbose".
can you offer any advice as to why the extra character '\' has been added to the string?
What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much.
ReplyDeleteΣίτες
"Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
ReplyDelete"