简体   繁体   中英

GET request to REST API in CRM Dynamics 365

I am attempting to use "R" to pull an entity table from our CRM Microsft Dynamcis 365 using the REST API and a GET request from the "httr" package.

When I enter the endpoint url directly into the browser, I am prompted to enter my CRM credentials (username and password) and I can view the succesful response in the browser.

When I try to perform a GET request in "R" I am doing the following:

username <- <my CRM username>
password <- <my CRM password>
endpoint_url <- "https://<organization name>/XXX/api/data/v8.2/<endpoint>"

GET(endpoint_url, authenticate(username,password,type = "basic"))

When I do this, I get the following error:

HTTP Error 401 - Unauthorized: Access is denied

Can someone please assist?

Much appreciated.

I dont think basic authentication works for the Web API, you need to use OAuth.

Authenticate to Dynamics 365 for Customer Engagement with the Web API

When you use the Web API for Customer Engagement or an on-premises Internet-facing deployment (IFD) you must use OAuth as described in Use OAuth to connect to Dynamics 365 for Customer Engagement for apps web Services.

If you're creating a single page application (SPA) using JavaScript you can use the adal.js library as described in Use OAuth with Cross-Origin Resource Sharing to connect a Single Page Application to Dynamics 365 for Customer Engagement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM