Sharepoint Rest api $batch endpoint not working for POST requests

Tomas Gil 11 Reputation points
2024-02-23T18:49:28.2966667+00:00

I'm trying to make a batch request using the $batch query option in sharepoint. The body of my request looks like this:

--batch_abcdefghijklmnopqrstuvwxyz
Content-Type: application/http
Content-Transfer-Encoding: binary

POST https://e.sharepoint.com/sites/J/_api/web/lists/GetByTitle('J')/items('2')/ValidateUpdateListItem HTTP/1.1
Accept: application/json;odata=nometadata

{
    "formValues": [
        {
            "FieldName": "Milestone",
            "FieldValue": "new milestone today - edit edit"
        },
    ],
    "bNewDocumentUpdate": true
}

--batch_abcdefghijklmnopqrstuvwxyz--

And I get the following error:

{"error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"en-US","value":"An invalid HTTP method 'POST' was detected for a query operation. Query operations only support the HTTP 'GET' method."}}}

Any idea why this is happening?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,610 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 34,741 Reputation points Microsoft Vendor
    2024-02-26T06:10:08.27+00:00

    Hi @Tomas Gil, You could refer to following code to update list items

    	var arr=[  
    	{  
    	   reqUrl:"https://brgrp.sharepoint.com/_api/Lists/Getbytitle('PlaceHolderList')/items(649)"  
    	   ,action:"UPDATE",  
    	   data:{__metadata:{type:"SP.Data.PlaceHolderListListItem"},Title:"Update Article_Using_Batch_2"}},  
    	   {  
    	      reqUrl:"https://brgrp.sharepoint.com/_api/Lists/Getbytitle('PlaceHolderList')/items(648)"  
    	      ,action:"UPDATE",  
    	      data:{__metadata:{type:"SP.Data.PlaceHolderListListItem"},Title:"Update Article_Using_Batch_1"}}  
    	   ];  
    	     
    	BatchUtils.PostBatchAll({rootUrl:"https://brgrp.sharepoint.com",  
    	batchUrls:arr}).then(r=>console.log(r));  
    

    ---If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.