Prefer: respond-async header doesn't work at microsoft graph api

Влад Луценко 0 Reputation points
2024-12-24T18:53:36.3966667+00:00

I'm trying to use microsoft graph api to make CRUD operations with excel files on onedrive.
As far as there is no way to update multiple non-adjacent ctlls in single request I'm tryung to use Prefer: respond-async header in my batch request.

const response = await this.client
  .api('/$batch')
  .header('Prefer', 'respond-async')
  .header('workbook-session-id', this.sessionId)
  .post({ requests: batchRequests });

but instead of getting 202 response, I'm waiting till my requests will be resolved and most of them (4/6) are failed with 429 error.

Need help to find the answer is there any way to update data in multiple non-adjusent cells or how should I use "prefer: respond-async" header so it would work for my requests.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,750 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhil Nasalwai - MSFT 165 Reputation points Microsoft Vendor
    2025-01-02T18:29:31.24+00:00

    Hello Влад Луценко,

    Thank you for contacting Microsoft!

    Regarding the header Prefer: respond-async, below work arounds might help in making the header work for the requests.

    • Ensure each request in the batch should be a separate object within the requests array.
    • 429 error usually indicates that you are hitting rate limits, this could be due to too many requests in a short period. Try adding delay between requests or using exponential backoff to handle rate limiting.
    • Since you are using Prefer: respond-async ensure your client is correctly handling asynchronous responses. You might need to implement a mechanism to poll for the status of the batch request until it's completed.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.