CRM WebApi 批量请求
CRM WebApi batch request
根据本指南:https://msdn.microsoft.com/en-us/library/mt607719.aspx,我正在尝试创建一个批处理请求以删除报价中的所有报价细节。
我正在使用 jquery 的 ajax 来执行请求:
$.ajax(
{
method: 'POST',
url: 'http://crm/api/data/v8.0/$batch',
headers: {
'Content-Type': 'multipart/mixed;boundary=batch_' + batchId,
'Accept': 'application/json'
},
data: 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--
我没有收到错误,但引用的细节没有被删除。
这是回复:
--batchresponse_a3304387-0e91-4097-b9f8-a207da3aa845--
我也找到了这个例子,我正在尝试用 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--
第一个不删除帐户,第二个不创建帐户。
关于我做错了什么的任何线索?
所以我做了一些进一步的测试并找出了问题所在。
首先,在上一个示例中,创建两个帐户,对象应该是这样的:
{ "name": "batch acount 2"}
而在第一个例子中,删除记录时,需要发送一个空对象。这是删除帐户的工作示例:
--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--
不知何故,批处理和变更集之前的两个破折号之一是不同的:
--batch_AAA123
--changeset_BBB456
我希望这对其他人也有帮助。
根据本指南:https://msdn.microsoft.com/en-us/library/mt607719.aspx,我正在尝试创建一个批处理请求以删除报价中的所有报价细节。 我正在使用 jquery 的 ajax 来执行请求:
$.ajax(
{
method: 'POST',
url: 'http://crm/api/data/v8.0/$batch',
headers: {
'Content-Type': 'multipart/mixed;boundary=batch_' + batchId,
'Accept': 'application/json'
},
data: 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--
我没有收到错误,但引用的细节没有被删除。 这是回复:
--batchresponse_a3304387-0e91-4097-b9f8-a207da3aa845--
我也找到了这个例子,我正在尝试用 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--
第一个不删除帐户,第二个不创建帐户。
关于我做错了什么的任何线索?
所以我做了一些进一步的测试并找出了问题所在。
首先,在上一个示例中,创建两个帐户,对象应该是这样的:
{ "name": "batch acount 2"}
而在第一个例子中,删除记录时,需要发送一个空对象。这是删除帐户的工作示例:
--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--
不知何故,批处理和变更集之前的两个破折号之一是不同的:
--batch_AAA123
--changeset_BBB456
我希望这对其他人也有帮助。