C# 批处理请求-Dynamics CRM
全部, 我正在尝试使用以下源代码实现对Dynamics CRM的批处理请求:C# 批处理请求-Dynamics CRM,c#,asp.net-web-api,dynamics-crm,C#,Asp.net Web Api,Dynamics Crm,全部, 我正在尝试使用以下源代码实现对Dynamics CRM的批处理请求: public async Task<HttpResponseMessage> HttpPatchCrmApi(string resource, string data) { string uniq = Guid.NewGuid().ToString(); MultipartContent content = new MultipartContent("mixed", "batch_" + u
public async Task<HttpResponseMessage> HttpPatchCrmApi(string resource, string data)
{
string uniq = Guid.NewGuid().ToString();
MultipartContent content = new MultipartContent("mixed", "batch_" + uniq);
HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + "/api/data/v8.0/$batch");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, CrmBaseUrl + resource);
request.Content = new StringContent(data, Encoding.UTF8, "application/json");
HttpMessageContent query = new HttpMessageContent(request);
content.Add(query);
batchRequest.Content = content;
HttpResponseMessage response = await RbWebApi.SendAsync(batchRequest);
return response;
}
在编写代码时,我从中获得灵感,我认为您的要求是错误的。 您必须准确地构建请求主体 <>这意味着空白行必须在正确的位置上,所有的属性都必须存在于正文中(例如“-change Sex.xxx”),如我所见,您不符合此要求。 我刚刚在Postman中针对我的CRM构建了一个请求,它成功了:
URL
https://yourTenant.api.crm.dynamics.com/api/data/v8.0/$batch
标题
OData-MaxVersion:4.0
OData-Version:4.0
Accept:application/json
Authorization:Bearer aVeryLongStringTokenHere
Content-Type: multipart/mixed;boundary=batch_1234567
身体
--batch_1234567
Content-Type:multipart/mixed;boundary=changeset_555666
--changeset_555666
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'BatchJobTest788'}
--changeset_555666
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{new_name: 'BatchJobTest348'}
--changeset_555666--
--batch_1234567--
附加备注:
- 标题的内容类型保存BatchId
- 批处理的内容类型包含ChangesetId(如果是数据更改)
- 在开始编程REST调用之前,请尝试在POSTMAN之类的REST工具中定义它们并使它们工作。然后在代码中构建工作请求
- CRM中批处理的一个很好的解释源
- 我认为你的要求是错误的。
您必须准确地构建请求主体
<>这意味着空白行必须在正确的位置上,所有的属性都必须存在于正文中(例如“-change Sex.xxx”),如我所见,您不符合此要求。
我刚刚在Postman中针对我的CRM构建了一个请求,它成功了:
URL
https://yourTenant.api.crm.dynamics.com/api/data/v8.0/$batch
标题
OData-MaxVersion:4.0
OData-Version:4.0
Accept:application/json
Authorization:Bearer aVeryLongStringTokenHere
Content-Type: multipart/mixed;boundary=batch_1234567
身体
--batch_1234567
Content-Type:multipart/mixed;boundary=changeset_555666
--changeset_555666
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1
POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{name: 'BatchJobTest788'}
--changeset_555666
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2
POST https://yourTenant.api.crm.dynamics.com/api/data/v8.0/accounts HTTP/1.1
Content-Type:application/json;type=entry
{new_name: 'BatchJobTest348'}
--changeset_555666--
--batch_1234567--
附加备注:
- 标题的内容类型保存BatchId
- 批处理的内容类型包含ChangesetId(如果是数据更改)
- 在开始编程REST调用之前,请尝试在POSTMAN之类的REST工具中定义它们并使它们工作。然后在代码中构建工作请求
- CRM中批处理的一个很好的解释源