0

I'm trying to use the new batch REST calls as documented here https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_batch.htm#topic-title

But I get the following;

My request body;

{"batchRequests":[
  {"method":"PATCH","url":"v34.0/sobjects/account/001D000000K0fXOIAZ","richInput":{"Name":"NewName"}},
  {"method":"GET","url":"v34.0/sobjects/account/001D000000K0fXOIAZ?fields=Name,BillingPostalCode"}
]}

The Response

[{"errorCode":"INVALID_BATCH_SIZE","message":"No requests found in batch request"}]

This was using services/data/v34.0/composite/batch.

Has anyone got a working example of this please?

  • 1
    Make sure you're setting the content-type header correctly (to application/json) – superfell Jun 17 '15 at 1:16
1

Todd,

What you are doing should definitely work. The endpoint you are posting to looks correct, and the payload is in the correct format. I would expect you to receive an error, but the error should be 404s since the account you are using does not exist in your system...not an invalid batch size error.

Would you be able to log a case with support and provide:

  • The specific way you are submitting the request (Workbench, curl, apex, some custom code)
  • Login access granted to your org
  • The org id for the org you are testing on

Once you have done that, respond with the case number and I can take a look on our side.

Thanks in advance. Jay

0

I would assume that since you are using the ID from the example:

001D000000K0fXOIAZ

That no records matched that ID and thus the query returns no records.

Simply replace the 001D000000K0fXOIAZ with the ID of an existing account in your org

The following works well when execute from the Dev Console but you need the correct ID

String bdy = '{"batchRequests":[{"method":"PATCH","url":"v34.0/sobjects/account/001A000000bK0KH","richInput":{"Name":"NewName"}},{"method":"GET","url":"v34.0/sobjects/account/001A000000bK0KH?fields=Name,BillingPostalCode"}]}';
HttpRequest req = new HttpRequest();
req.setEndpoint('https://cs7.salesforce.com/services/data/v34.0/composite/batch');
req.setMethod('POST');
req.setBody(bdy);
req.setHeader('content-type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + userinfo.getSessionID());
HttpResponse res = new Http().send(req);
system.debug(logginglevel.error,res);
  • That is worth a shot... thanks. My thinking however is that it would still result in response relating to the sub-operation, rather than one referencing the batch request itself. I shall tweak this to reflect a REST call that I first validate works outside of the batch. – Todd Halfpenny Jun 16 '15 at 21:02
  • I have tried with IDs that I know exist and return values, still no joy sadly. – Todd Halfpenny Jun 16 '15 at 21:23
0

The issue was the Content-Type being set incorrectly... D'oh!

I initially tried my request using curl instead and this worked. Here's the command I used (I have masked my accessToken);

curl https://eu5.salesforce.com/services/data/v34.0/composite/batch \
  -H 'Authorization: Bearer <MY-ACCESS-TOKEN>' \
  -H "Content-Type: application/json" \
  -X POST \
  -d'{"batchRequests":[{"method":"GET","url":"v34.0/sobjects/account/00124000003Q4MF?fields=Name,BillingPostalCode"}]}'

I was using the forcejs library in my original query, and I had mistakenly assumed that the default content-type was json. Once I had set this correctly then my calls went through just fine.

Thanks all for you help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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