从邮递员到 Microsoft Dynamics crm 365 的 POST/GET 请求邮递员、Dynamics、Microsoft、crm

2023-09-07 10:34:59 作者:敷衍怎么演

我试图使用 Web API 创建实体.因此,使用我的实例 url、client_id、client_secret 我可以成功生成访问令牌和刷新令牌.但是,每当我尝试使用该 access_token 发出任何发布请求时,我都会得到 401(未授权)状态.我试图从邮递员创建新实体,如下所示:网址:https://myurldomain.crm5.dynamics.com/api/data/v9.0/accounts

I was trying to create entity using Web API. So using my instance url, client_id, client_secret I can successfully generate access token and refresh token. But whenever I try to make any post request using that access_token, I get 401(unauthorized) status. I was trying to create new entity from postman like this: url: https://myurldomain.crm5.dynamics.com/api/data/v9.0/accounts

标题:

POST /api/data/v9.0/accounts HTTP/1.1
Host: myinstancename.crm5.dynamics.com
Content-Type: application/json; charset=utf-8  
Authorization: Bearer  mytoken
OData-Version: 4.0
OData-MaxVersion: 4.0
Accept: application/json

[从邮递员代码部分复制]正文:

{
    "name": "Sample Account",
    "creditonhold": false,
    "address1_latitude": 47.639583,
    "description": "This is the description of the sample account",
    "revenue": 5000000,
    "accountcategorycode": 1
}

在发送请求时,我不断收到 401 未经授权的响应.请问有什么建议吗?我正在关注他们的 API

While send request, I constantly get 401 unauthorized response. Any suggestion please? I am following their API

推荐答案

按照 MS 文档设置 Postman 环境 &使用相同的执行操作:将 Postman 与 Dynamics 365 Web API 结合使用

Follow the MS documentation to setup the Postman environment & using the same to perform operations: Use Postman with the Dynamics 365 Web API

设置 Postman 环境时,请确保在 Azure AD 登录质询弹出窗口中使用 CRM 用户凭据,该弹出窗口至少具有一个安全角色,涵盖 CRM 中的必要权限.如果您能够在 CRM UI 中创建帐户记录,那么也可以在 Postman 中使用您的凭据.

When you setup the Postman environment, make sure you use the CRM user credentials in Azure AD signin challenge popup, which has minimum of one security role covering the necessary privileges in CRM. If you are able to create an Account record in CRM UI, then use your credentials in Postman too.

要管理您在 Postman 中用于连接的任何 CRM 用户的角色,请检查 CRM 中的设置"-安全"-用户"下的用户配置文件".如果需要,可以从销售人员角色开始.

To manage roles for any CRM user you are using to connect in Postman, check that User profile in CRM under Settings - Security - Users. Start with Sales person role if you want.

为用户分配安全角色

获取令牌是 O365 & 处理的第一部分.任何有效 AD 用户的 AAD,但 API 请求使用该令牌 &将 web api 发布到 CRM 在线平台,CRM 安全模型将在该平台启动 &授权数据访问.

Getting a token is first part handled by O365 & AAD for any valid AD user, but the API request uses that token & issue the web api to CRM online platform where the CRM security model will kick in & authorize the data access.