Advertisements

Microsoft Flow – Update a List item with a people field using REST API in the Send an HTTP request to SharePoint action

Reasons for using the REST API

This post includes quite a few common requirements. So before I get started I’ll list  some of the subjects that you might be interested in:

  • Update a list item with the REST API
  • Update a people field with the REST API
  • Using the Send an HTTP request to SharePoint action
  • Extra Bonus – Update the Modified By field!

Today I saw a question on the Flow forum “My flow is changing Modified By to me”. This is a common issue where people use one account to update the flows in Microsoft Flow and then all modified by accounts are set to the flow author.

Send an HTTP request to SharePoint

Although I might not be able to avoid it being set to the flow author, I might be able to set it back, although most likely you are updating the triggering item from within the flow. By using the Send an HTTP request to SharePoint action you might find that you have more control over the Modified By field.

Send an HTTP request to SharePoint action updating an item

I’m first of all assuming that you know who the user is that modified the list item (most likely this is the Modified By field before you updated the item within the flow!).  In my example I’m assuming that the user Id of my user is 17. This number matches the user id as you can find it within SharePoint’s hidden user list (still remember that list?). For my test I simply went to modify a list item and then visited the …./items(13) url which gave me the user id of the user account that I was interested in. This of course could also be done within Microsoft Flow.

In the above screenshot you will notice that I’m updating the EditorId field rather than the Editor (this is the internal name for the Modified By field). Simply take your people field and add a postfix of Id.

Ok, that is easy! There is one important note however to update the Modified By user you will need to be site collection administrator. Therefore if you need a flow to update the Modified By user within your flow then you might want to create it as an administrator.

Other interesting posts

Microsoft Flow – How to clear fields in SharePoint list items

Advertisements

21 thoughts on “Microsoft Flow – Update a List item with a people field using REST API in the Send an HTTP request to SharePoint action

  1. commented on July 4, 2018 by Sylvie

    Thanks for this Pieter!
    Maybe a stupid question here, but does this mean you need to know the previous modifier each time? I’m interested in setting it dynamically, so more of a “Get previous Modified By” and then set Modified By to that person. But in the workflow above it looks like it would be static, no?

    Thanks again for your time on this!
    Sylvie

    • commented on July 4, 2018 by Pieter Veenstra

      Hi Silvie, I would expect that when a person trigger a flow that the current modified by user is the actual user that you are interested in, but I might be missing something.

      • commented on July 5, 2018 by Sylvie

        Yes that’s what I want! Right now this is how it works:

        John Smith uploads a document and the flow is automatically triggered, however because I created the flow, the Modified By changes to me.

        I just want the Modified By to be John Smith.
        But I need this to work for all of my users, so I need it to be dynamic.
        Does that make sense?

        Thanks so much

      • commented on July 5, 2018 by Pieter Veenstra

        Hi Silvie,

        You will need to set a variable to triggerbody()[‘Editor’] Then add a condition that checks that your editor isn’t the flow owner. If it is exit out from the flow. Then when you do an updates make sure that you set the modified by owner as described in this article.

  2. commented on July 16, 2018 by Brett R

    Hi all, I thought it’s worth mentioning for anyone else that stumbles across this. I tested this functionality using Microsoft Flow & REST API to keep Modified By the same as the original uploader of a file & it doesn’t work.

    As of 16/07/2018 I’m pretty certain that you can only retain ‘Modified By’ details using CSOM. It isn’t supported using a HTTP Request/REST API.

    This is due to an implementation of the SystemUpdate() Method that was applied to CSOM in SharePoint Online, however that same functionality of updating properties without a new version has not yet been implemented for REST API

    For information regarding this see:
    https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/32021398-enable-listitem-systemupdate-via-rest
    https://sites.google.com/site/sharebyme/sharepoint/update-vs-systemupdate-for-sharepoint-list-item

    • commented on July 16, 2018 by Pieter Veenstra

      Hi Brett, thank you for your comment. I just tried it again and it still works. I’m running my flow as an administrator within my tenant and I set the editor of my list item to a guest user within my tenant.

      • commented on July 17, 2018 by Brett R

        Oh sorry I didn’t mention the most important point lol.

        You’re right, it does work with LISTS. However the functionality doesn’t work with Libraries 🙁 Or at least that’s what my testing has shown so far.

      • commented on July 17, 2018 by Pieter Veenstra

        Hi Brett,

        That is right. I’ve not managed to do this for documents either.

  3. commented on August 23, 2018 by NewBie

    Thanks for sharing this Pieter, I have been trying to create a list item using Send an HTTP request in MS Flow. Can you please let me know how can we insert a list item using REST API in MS FLOW.

    • Hi, thank you for your comment. I am planning a series of posts about RESTAPI and Flow starting next week. I wil include the list item creation in these posts.

      • commented on August 24, 2018 by NewBie

        Thanks for considering my request. Looking forward to the series. I have also found your other blog posts about MS flow quite useful. Thanks.

  4. commented on September 17, 2018 by jonocayo

    Hi Pieter:

    Excellent article. Jist wonder how can you get the user ID of the iser that is modifying the flow and send it as parameter to the REST API URI. Is there an instruction in flows to get that value? Thanks in advance.

    Regards.

    • Do you mean the user that triggered the flow? Or do you want the owner of the flow who developed the flow?

      • commented on September 17, 2018 by jonocayo

        Hi. Yes the user that triggered the flow so I can update depending on who modified the list item. Thank!!

      • I think that the trigger may give you the modified by user. ( i am not near a flow system at the moment) if not you could try an http request action and use as the uri _api/web/lists/getbytitle(‘listname’)/items(itemid) to get all the details of the list item. If you need more help on this, I can have a look tomorrow.

  5. commented on April 12, 2019 by ItsBradMorganBrad Morgan

    This does not work for me and I am using a site collection admin / tenant admin account to author the Flow.I am not getting any errors…the update never happens…what am I doing wrong?

    {‘__metadata’: { ‘type’: ‘SP.Data.Ask_x0020_the_x0020_PresidentListItem’ }, ‘Title’: ‘Title’,’AuthorId’: 39,’EditorId’: 39 }

    • Hi Brad, Can you send me a screenshot of the full configuration of the action? Feel free to email be on contact@veenstra.me.uk

      In my example I only updated the editorId. Could you remove the AuthorId bit and see if that makes any difference?

  6. commented on May 29, 2019 by hikmat

    Hi Pieter,

    I just sent you an email with screenshots but it doesn’t work for me, other fields in the same request gets updated but not Modified by. I am also getting a response 204 for some reason instead of 200.

    Thanks,

    • commented on May 30, 2019 by Pieter Veenstra

      I’ve just tried this in my environment and I can’t make this work for the EditorId field anymore. I’m seeing the same 204 being returned. So I guess the only thing you could now do is to update a different user field with the method above.

      • commented on May 30, 2019 by hikmat

        Thanks for the help Pieter.

Leave a Reply to Pieter Veenstra Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: