【发布时间】:2019-09-05 06:47:22
【问题描述】:
我是 CRM 新手。我已经为应用程序实现了 OAuth。我正在使用 web api 方法来访问特定的 CRM 用户数据。我已经成功地为“获取用户机会”、“更新用户机会”实现了 web api。但我无法为“关闭机会”或“赢得机会”做同样的事情。
注意:我在访问用户数据时没有使用 OrganizationService 代理。我正在使用 OAuth 令牌并调用特定的 API 请求 URL。
请指导我实现同样的目标。如果有人可以在代码中展示任何示例以及如何在邮递员中进行测试,那将是非常值得赞赏的。
我的查询:
1) 是否可以使用 OAuth 令牌,我们可以在不传递用户凭据的情况下连接到 OrganizationServiceProxy 吗?
例如:获得机会
请求网址:https://testdevcrm.crm8.dynamics.com/api/data/v9.1/opportunities
标题:
授权:承载(accessToken)
接受:应用程序/json
OData-MaxVersion:4.0
OData-版本:4.0
方法类型:GET
代码
#region FectchUserOpportunities
public async Task<JToken> FectchUserOpportunities(string systemuserid,string bearerToken)
{
JToken jResu = null;
try
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string filter = "&$filter=_createdby_value eq '" + systemuserid + "' and opportunityid ne null and statuscode eq 1&$orderby=createdon asc&$top=5";
string opportunitiesURL = string.Concat(GenericMethods.GetAppSetting("FetchCRMOpportunitiesAPI"), filter);
var result = httpClient.GetAsync(opportunitiesURL).Result;
if (result != null)
{
var opporJSON = await result.Content.ReadAsStringAsync();
JToken jsonResult = JsonConvert.DeserializeObject<JObject>(opporJSON);
jResu = jsonResult["value"];
}
else
{
jResu = null;
}
}
catch (Exception ex)
{
}
return jResu;
}
#endregion
【问题讨论】:
-
你的问题解决了吗?
-
您没有使用 MS SDK 的任何原因?
-
@AnkyUser,我发布了非常适合我的答案。
-
@daryl,你的意思是 CRM 的 nuget 包吗?
-
是的。如果您使用的是 .Net 框架,那么他们为什么不使用它呢?
标签: c# asp.net-web-api dynamics-crm dynamics-crm-2011 crm