With this guide: .aspx, I'm trying to create a batch request to delete all quotedetails on a quote. I'm using jquery's ajax to do the request:
$.ajax(
{
method: 'POST',
url: 'http://crm/api/data/v8.0/$batch',
headers: {
'Content-Type': 'multipart/mixed;boundary=batch_' + batchId,
'Accept': 'application/json'
},
data: payload
});
And this is the payload:
–batch_SuL11egVC7
Content-Type:multipart/mixed;boundary=changeset_Sj74vxbGYr
–changeset_Sj74vxbGYr
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
DELETE crm/.../quotedetails(cc9b9ba8-4570-e611-80ba-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
–changeset_Sj74vxbGYr
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
DELETE crm/.../quotedetails(cd9b9ba8-4570-e611-80ba-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
–changeset_Sj74vxbGYr--
-batch_SuL11egVC7--
I'm not getting an error, but the quotedetails aren't deleted. This is the response:
--batchresponse_a3304387-0e91-4097-b9f8-a207da3aa845--
I've also found this example and I'm trying to replicate it with Postman: Batch request - Dynamics CRM
Headers:
Content-Type:multipart/mixed;boundary=batch_123456
Accept:application/json
Odata-MaxVersion:4.0
Odata-Version:4.0
Body:
–-batch_123456
Content-Type:multipart/mixed;boundary=changeset_123457
–-changeset_123457
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
POST http://onpremisesurl/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'batch acount 1'}
–-changeset_123457
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
POST http://onpremisesurl/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'batch acount 2'}
–-changeset_123457--
--batch_123456--
The first one doesn't delete the accounts and the second doesn't create the accounts.
Any clues on what I'm doing wrong?
With this guide: https://msdn.microsoft./en-us/library/mt607719.aspx, I'm trying to create a batch request to delete all quotedetails on a quote. I'm using jquery's ajax to do the request:
$.ajax(
{
method: 'POST',
url: 'http://crm/api/data/v8.0/$batch',
headers: {
'Content-Type': 'multipart/mixed;boundary=batch_' + batchId,
'Accept': 'application/json'
},
data: payload
});
And this is the payload:
–batch_SuL11egVC7
Content-Type:multipart/mixed;boundary=changeset_Sj74vxbGYr
–changeset_Sj74vxbGYr
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
DELETE crm/.../quotedetails(cc9b9ba8-4570-e611-80ba-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
–changeset_Sj74vxbGYr
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
DELETE crm/.../quotedetails(cd9b9ba8-4570-e611-80ba-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
–changeset_Sj74vxbGYr--
-batch_SuL11egVC7--
I'm not getting an error, but the quotedetails aren't deleted. This is the response:
--batchresponse_a3304387-0e91-4097-b9f8-a207da3aa845--
I've also found this example and I'm trying to replicate it with Postman: Batch request - Dynamics CRM
Headers:
Content-Type:multipart/mixed;boundary=batch_123456
Accept:application/json
Odata-MaxVersion:4.0
Odata-Version:4.0
Body:
–-batch_123456
Content-Type:multipart/mixed;boundary=changeset_123457
–-changeset_123457
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
POST http://onpremisesurl/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'batch acount 1'}
–-changeset_123457
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
POST http://onpremisesurl/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'batch acount 2'}
–-changeset_123457--
--batch_123456--
The first one doesn't delete the accounts and the second doesn't create the accounts.
Any clues on what I'm doing wrong?
Share Improve this question edited Sep 15, 2016 at 8:04 CodeNomad42 asked Sep 15, 2016 at 7:26 CodeNomad42CodeNomad42 9637 silver badges20 bronze badges1 Answer
Reset to default 7So I'v done some further testing and found out where it goes wrong.
First, in the last sample, creating two accounts, the object should be this:
{ "name": "batch acount 2"}
And in the first example, when deleting records, you need to send an empty object. This is a working example for deleting accounts:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
DELETE http://tenanturl/api/data/v8.1/accounts(4deb1677-427b-e611-80bb-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
{}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
DELETE http://tenanturl/api/data/v8.1/accounts(52eb1677-427b-e611-80bb-0050568a6c2d) HTTP/1.1
Content-Type: application/json;type=entry
{}
--changeset_BBB456--
--batch_AAA123--
And somehow one of the two dashes before batch and changeset was different:
--batch_AAA123
--changeset_BBB456
I hope this helps somebody else as well.