How to create Dynamics CRM Online User License

本文介绍如何通过O365 API在CRM Online环境中创建用户并分配许可。首先介绍了O365 API的基本概念及如何调用这些API来完成任务,包括创建用户账户、设置账户属性及分配Office 365许可证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    Hi, guys. Today I would like to share your guys how to operate CRM Online through O365 APIs. This is a very new topic because O365 APIs just went into Preview program.

    Can we create CRM online user using  CRM OOB APIs? No, imagine that if you want to create a user in on premise environment, then you should create an account in AD first, and then create an CRM account using created AD account. As same as on premise environment, we also need to create an online AD account in Azure AD first.

    OK, let's break up the confused concept. What's O365 APIs? O365 is office 365, Microsoft was migrated all of office suit software e.g. word, excel, sharepoint, exchange and so on into Cloud environment. And they are got very user experience for integration. Image that you just need to buy one software, and then you can use all of competition software on longer do anything for configurations or setups. For O365 APIs, it was expose to end-developer to invoke to control resources of Office 365 such creating an calendar, sending email, creating user, assigning user license and so on.

   In this article, we will follow below steps to describe this topic:

1. How to invoke O365 APIs.

Microsoft had published one VS extension tool. It can generate sample codes about how to invoke O365 services.


2. How to use O365 APIs to create CRM Online user

Right now Microsoft was expose oen type APIs called Azure AD graph based web api to us to operate CRM Online user. And there is one helper library can be used to operate CRM Online user, you guys can download it in here. Below is a code snipet about how to user it to create CRM Online user.

            string userName = new Random().Next(1000, 9999).ToString();
            var verifiedDomains = DDS.tenantDetails.Single().verifiedDomains.ToList();
            var verifiedDomainValues = verifiedDomains.Select(it => it.name);
            ViewData["selectedDomain"] = new SelectList(verifiedDomainValues);

            Microsoft.WindowsAzure.ActiveDirectory.User user = new Microsoft.WindowsAzure.ActiveDirectory.User();
            user.userPrincipalName = string.Format(CultureInfo.InvariantCulture, "{0}@{1}", userName, "crm2014.onmicrosoft.com");
            user.mailNickname = userName;
            user.displayName = userName;
            user.accountEnabled = true;
            user.passwordProfile.password = "123456";

            DDS.AddTousers(user);
            DDS.SaveChanges();


3. How to assign O365 license to created CRM Online user

We still can't use the created account after assiging a license to it. So we need to use below code to assign a license to the created account.

string[] queryParameters = { "api-version=2013-11-08" };

            string requestUrl = String.Format(CultureInfo.InvariantCulture,
              "{0}/{1}/users/{2}/assignLicense?{3}",
              serviceInfo.ApiEndpoint,
              HttpUtility.UrlEncode(Office365CommonController.TenantId),
              HttpUtility.UrlEncode(user.userPrincipalName),
              String.Join("&", queryParameters));

            // Prepare the HTTP request:
            using (HttpClient client = new HttpClient())
            {
                Func<HttpRequestMessage> requestCreator = () =>
                {
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
                   
                    request.Content =new StringContent(@"{
                              'addLicenses':[{'disabledPlans':[ ],'skuId':'d17b27af-3f49-4822-99f9-56a661538792'}],
                              'removeLicenses':[ ]}",System.Text.Encoding.UTF8,"application/json");
                    return request;
                };

                // Send the request using a helper method, which will add an authorization header to the request,
                // and automatically retry with a new token if the existing one has expired.
                using (HttpResponseMessage response = await Office365CommonController.SendRequestAsync(
                    serviceInfo, client, requestCreator))
                {
                    // Read the response and deserialize the data:
                    string responseString = await response.Content.ReadAsStringAsync();
                    if (!response.IsSuccessStatusCode)
                    {
                        return Office365CommonController.ShowErrorMessage(serviceInfo, responseString);
                    }

                    
                    return View();
                }
            }


        }


Resources

Office 365 APIsAuthority Documents

http://msdn.microsoft.com/en-us/library/office/dn605892.aspx

 

Office 365 API forVisual Studio 2013 Extension

http://visualstudiogallery.msdn.microsoft.com/7e947621-ef93-4de7-93d3-d796c43ba34f


Office 365 API Workthrough

http://blogs.msdn.com/b/officeapps/archive/2014/03/12/announcing-office-365-api-tools-for-visual-studio-preview.aspx


Announcing the new version of the Graph API: api-version=2013-11-08( how to assign license to users)

http://blogs.msdn.com/b/aadgraphteam/archive/2013/11/14/announcing-the-new-version-of-the-graph-api-api-version-2013-11-08.aspx>








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值