2016-09-15 140 views
7

有了本指南:https://msdn.microsoft.com/en-us/library/mt607719.aspx,我試圖創建批量請求以刪除報價單上的所有報價單。 我使用jQuery的Ajax的要求去做:CRM WebApi批量請求

$.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-- 

我沒有得到一個錯誤,但quotedetails不會被刪除。 這是響應:

--batchresponse_a3304387-0e91-4097-b9f8-a207da3aa845-- 

,我也發現了這個例子,我試圖與郵差複製它:Batch request - Dynamics CRM

頁眉:

Content-Type:multipart/mixed;boundary=batch_123456 
Accept:application/json 
Odata-MaxVersion:4.0 
Odata-Version:4.0 

身體:

–-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-- 

第一個不刪除帳戶,第二個不創建帳戶。

我做錯了什麼線索?

回答

2

所以我做了一些進一步的測試,發現它出錯的地方。

首先,過去的樣品中,創建了兩個賬戶,對象應該是這樣的:

{ "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 

我希望這可以幫助別人也是如此。