1

When i try to execute sample batch code in Sharepoint server 2013 i'm getting the error 'Cannot find resource for the request $batch'

Int16 listRetrievalCount = 0;

        if (IsPostBack)
        {
            // Get the host web's URL.
            sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
        }

        // Create the parent request
        var batchRequest = new BatchODataRequest(String.Format("{0}/_api/", sharepointUrl)); // ctor adds "$batch"
        batchRequest.SetHeader("Authorization", "Bearer " + accessToken);

        using (var oDataMessageWriter = new ODataMessageWriter(batchRequest))
        {
            var oDataBatchWriter = oDataMessageWriter.CreateODataBatchWriter();
            oDataBatchWriter.WriteStartBatch();

            // Create the two child query operations.
            oDataBatchWriter.CreateOperationRequestMessage(
                 "GET", new Uri(sharepointUrl.ToString() + "/_api/Web/lists/getbytitle('Composed Looks')/items?$select=Title"));
            listRetrievalCount++;

            oDataBatchWriter.CreateOperationRequestMessage(
               "GET", new Uri(sharepointUrl.ToString() + "/_api/Web/lists/getbytitle('User Information List')/items?$select=Title"));
            listRetrievalCount++;

            oDataBatchWriter.WriteEndBatch();
            oDataBatchWriter.Flush();
        }

        // Parse the response and bind the data to the UI controls
        var oDataResponse = batchRequest.GetResponse();

Eorror is thrown in GetResponse function. Code taken from https://msdn.microsoft.com/library/office/dn903506.aspx

2 Answers 2

0

Are you using this code against SharePoint Online / O365 or against an on-premise SharePoint server? AFAIK, the $batch operation is supported only in case of the former ones, see this post:

SharePoint Online and the Office 365 APIs implement the OData $batch query option

3
  • i'm tring in the on-premise SharePoint server. it will work ? Apr 29, 2015 at 12:55
  • No, based on my experience and based on the official documentation I referred to, it won't.
    – pholpar
    Apr 29, 2015 at 13:14
  • When i excute code i'm getting the CONTENT-TYPE as 'application/atom+xml;type=feed;charset=utf-8' in response. Is there any way to get the json in response Apr 30, 2015 at 6:08
0

There is an option to fall back to 2010 batch operation. but but you won't be able to use listdata.svc if you need something not related to the Lists

/_vti_bin/listdata.svc/$batch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.