Improve my API Calls to SharePoint inside my PowerAutomate by using Batch requests instead of using Build-in Functions inside loop

I have this Child Power Automate flow that is been called 3,000 times each day from different automated and scheduled flow all over our solution.

The flow manually does those main actions: -

  1. Accepts a list GUID + Item ID
  2. Stop Permission inheritance of the Item.
  3. Iterate over all the Item Permissions >> Remove Them >> Reassign them with Read.

As follow: -

enter image description here

enter image description here

So now if we take an example where the list item has 7 permission been granted to it from the list, then the flow will be performing those number of requests: -

  1. 1 request to Break the Permission Inheritance

  2. 1 request to Get all Permissions (For example 7 permissions)

  3. 2 Requests inside each ApplyToEeach Iteration, so total requests will be 14

So total requests for each flow run will be = (1 + 1 + 14) = 16 requests

Now i am trying to use Batch calls to reduce the number of requests been generated + improve the performance.

Here is my plan :-

1- Combine the first 2 calls into one POST Patch call, as follow:-

--batch_1234
Content-Type: multipart/mixed; boundary="changeset_1234"

--changeset_1234
Content-Type: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

POST https://**.sharepoint.com/_api/web/lists/GetByTitle('WorkOrder')/items(1)/breakroleinheritance(true) HTTP/1.1

--changeset_1234
Content-Type: application/json
Content-Type: application/http
Content-Transfer-Encoding: binary

POST https://**.sharepoint.com/_api/web/lists/GetByTitle('WorkOrder')/items(2)/roleassignments/roleassignments HTTP/1.1
    
--changeset_1234--
--batch_1234--

2- Combine the 2 actions of removing the Permission and reassign them with Read, by one Batch call.

3- So, the flow should be doing those numbers of calls: -

1-Batch-Call + (1 * 7) = 8 requests instead of 16. which is a good way to start with.

But I have those 2 main questions: -

  1. When I do the first Batch call, how I can get the results from calling the second POST request, which is responsible for getting all the permission items after breaking the permission inheritance, so i can loop thorough them?

  2. If I want to be more optimistic, can I combine all the calls inside the loop into one Batch? so my flow will be only running 2 requests?

My plan to do 2 main improvements:-

  1. Improve the performance
  2. Force my power automate flow to do less Requests. keeping in mind that doing an API call to SharePoint is considered as one request, also initializing a variable or setting a variable is considered as 1 request also.

Thanks in advance for any help.

Regards

Upvotes: 0

Views: 64

Answers (0)

Related Questions