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

22 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. 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

    1. 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.

      1. 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

      2. 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. 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

    1. 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.

      1. 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.

  3. 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.

      1. 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. 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.

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

      2. 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. 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 }

  6. This does not work for me using a Site Collection Admin / Tenant admin as the Flow author. It succeeds without an error…what am I doing wrong?

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

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

    1. 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.

Leave a Reply to Sylvie Cancel reply

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

%d bloggers like this: