将角色与用户相关联Microsoft Dynamics CRM(Rest API)

我有用例,需要创建角色,在crm实例中创建用户并将角色与用户相关联。


我已经探索了用于创建用户和创建角色的api。


下面是代码:


private void createUser(IntegrationUserDTO integrationUserDTO, STSDto stsDetails, CRMAuthContext crmAuthContext)

            throws IntegrationsException {

        Map<String, Object> requestBody = new HashMap<>();

        URI uri = new MSCRMHttpDelegate().odataUriBuilder(crmAuthContext.getCrmApiUrl())

                .appendEntitySetSegment("systemusers").build();

        HttpPost httpPost = new HttpPost(uri.toString());

        httpPost.setHeader("Authorization", "Bearer " + crmAuthContext.getAccessToken());

        httpPost.setHeader("Accept", MediaType.APPLICATION_JSON);

        httpPost.setHeader("OData-MaxVersion", "4.0");

        httpPost.setHeader("OData-Version", "4.0");

        httpPost.setHeader("Content-Type", "application/json");


        requestBody.put("accessmode", "4");

        requestBody.put("applicationid", UUID.fromString(stsDetails.getClientId()));

        requestBody.put("firstname", integrationUserDTO.getUsername());

        requestBody.put("lastname", integrationUserDTO.getSecretToken());

        requestBody.put("internalemailaddress", integrationUserDTO.getExtraParams());

        requestBody.put("isintegrationuser", true);

        MSCRMUser user = getBusinessUnitId(crmAuthContext);


        if (StringUtils.isNoneBlank(user.getBusinessUnitId())) {

            requestBody.put("businessunitid@odata.bind",

                    "/businessunits(" + UUID.fromString(user.getBusinessUnitId()) + ")");

        }

我找不到任何将用户与角色关联的Rest API。我看过Soap API,但没有看到其他的API。我在Dynamics CRM文档中进行了探索,但没有发现与实体角色关联相关的任何信息。有谁知道任何其他api将角色与用户相关联吗?


繁星点点滴滴
浏览 190回答 2
2回答

慕工程0101907

您可以使用Web API发送请求,以将用户与给定角色相关联。用户和角色之间的关系称为systemuserroles_association。因此,您应该发送以下格式的请求:POST [Organization URI]/api/data/v9.0/systemusers(00000000-0000-0000-0000-000000000002)/systemuserroles_association/$ref HTTP/1.1&nbsp; &nbsp;Content-Type: application/json&nbsp; &nbsp;Accept: application/json&nbsp; &nbsp;OData-MaxVersion: 4.0&nbsp; &nbsp;OData-Version: 4.0&nbsp;&nbsp;{&nbsp;&nbsp;"@odata.id":"[Organization URI]/api/data/v9.0/roles(00000000-0000-0000-0000-000000000001)"&nbsp;&nbsp;}&nbsp;&nbsp;

噜噜哒

只是为别人解雇使用邮递员,您可以通过以下两种格式发送请求:https:// [orgurl] /api/data/v9.0/systemusers(bc70f5c3-8800-ea11-a814-000000000000)/ systemuserroles_association /&nbsp;$ ref?$ id =&nbsp;https:// [orgurl] / api / data / v9 .0 /角色(00000000-9519-e911-817c-000000000000)https:// [orgurl] /api/data/v9.0/systemusers(bc70f5c3-8800-ea11-a814-000000000000)/ systemuserroles_association(00000000-9519-e911-817c-000000000000)/&nbsp;$ ref
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java