我已使用 C# 和 Azure 连接到我的 CRM。我的要求是我需要仅使用WebAPI创建实体记录。在早期版本中,我使用过 IOrganization 服务并且运行良好。现在,我需要切换到 WebAPI。 我能够使用 webapi 读取记录,但不知道如何创建记录。 我尝试在网络上搜索,但找不到任何相关的文章/教程。 任何帮助,将不胜感激。 提前致谢。
最佳答案
This documentation就是您正在寻找的。正如您已经提到的,您可以使用 Web api 读取记录,您可以使用下面的代码片段在 C# 中使用 Web api 创建新的联系人记录。
JObject contact1 = new JObject();
contact1.Add("firstname", "Peter");
contact1.Add("lastname", "Cambel");
HttpRequestMessage createRequest1 = new HttpRequestMessage(HttpMethod.Post, https://xyz.crm.dynamics.com/api/data/v9.0/contacts");
createRequest1.Content = new StringContent(contact1.ToString(), Encoding.UTF8, "application/json");
HttpResponseMessage createResponse1 = await httpClient.SendAsync(createRequest1);
if (createResponse1.StatusCode == HttpStatusCode.NoContent) //204
{
Console.WriteLine("Contact '{0} {1}' created.", contact1.GetValue("firstname"), contact1.GetValue("lastname"));
contact1Uri = createResponse1.Headers.GetValues("OData-EntityId").FirstOrDefault();
entityUris.Add(contact1Uri);
Console.WriteLine("Contact URI: {0}", contact1Uri);
}
else
{
Console.WriteLine("Failed to create contact for reason: {0}", createResponse1.ReasonPhrase);
throw new CrmHttpResponseException(createResponse1.Content);
}
关于c# - 仅使用 WebAPI 创建 Dynamics 365 实体记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53812242/