Reputation: 263
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.
Upvotes: 1
Views: 2556
Reputation: 17562
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.
Upvotes: 1