Solved Authentication to call Dynamic 365 CRM API

Status
Not open for further replies.

Tin Nwe Win

Gold Partner
Joined
Jul 3, 2021
Messages
218
Reaction score
25
Can you please help me with how to do Authentication to call Dynamic 365 CRM API?

Thank you in advance for your help.
 

Attachments

  • 1645117920156.png
    1645117920156.png
    37.3 KB · Views: 20
The Edit button is at the bottom of each post you write:
1647956855242.png

In any case, if you revoke the token, the information will not be valid anymore, so no need to delete the attachment.
 
@edossantos

If I revoke the token, will it effect on the other connected system via this account because CRM has connected with other system via this client id?

Could you please help me delete this attachment only?
 
I don't see the attachments anymore.
 
I don't see the attachments anymore.
Yes. I just reported that post to remove only attachments. Now they has been removed already.
Thank you @edossantos.
For C# code, I will try it and update the status
 
  • Like
Reactions: edossantos
@edossantos

I got refresh token with C# code with your help.
But, when I try to invoke CRM OAuth Token API, it returns 400 the below status code.

ResponseStatusCode='400' - ResponseContent: {"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: d4c1910d-b0b4-4ec6-93f3-c190887d0201\r\nCorrelation ID: da5a9348-f3e1-416e-90b5-9b10b1e6789b\r\nTimestamp: 2022-03-23 10:55:19Z","error_codes":[900144],"timestamp":"2022-03-23 10:55:19Z","trace_id":"d4c1910d-b0b4-4ec6-93f3-c190887d0201","correlation_id":"da5a9348-f3e1-416e-90b5-9b10b1e6789b","error_uri":"https://login.microsoftonline.com/error?code=900144"}


This is my content to invoice API. grant_type has included.

1648033777140.png
1648033412951.png
 
The Content Type should be set to application/x-www-form-urlencoded, it's not JSON.

Maybe that confuses their server...
 
  • Like
Reactions: Evolute IT
@edossantos

I got it Assess Token.
But, I got 400 error when I try to call CRM API to update contact timeline activities.

ResponseStatusCode='400' - ResponseContent: {"error":{"code":"0x0","message":"An error occurred while validating input parameters: System.ArgumentException: Stream was not readable.\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext.CreateTextReader(Stream messageStream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext..ctor(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.Json.ODataJsonFormat.CreateInputContext(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.ODataMessageReader.ReadFromInput[T](Func`2 readFunc, ODataPayloadKind[] payloadKinds)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"}}
2022/03/23 18:19:02.150|4736|0014|Trc|CallPair._testing.Main_17.Main.3510.[C:1308.2]-From script: Testing - CallID 00000C16E752038E_1308 - Callflow - Start executing component 'mainAutoAddedFinalDisconnectCall'

1648036747229.png

1648036778467.png
 
Now in this request you should be sending JSON, but you're sending URL encoded form data.... Check the API specification to understand the payload you need to include in your request.
 
@edossantos

I send with content type application/json

1648041387510.png
 
  • Like
Reactions: Tin Nwe Win
@edossantos

Please help... I have no idea.....API is working with Postman


Thank You
 
Yes, the Content Type is fine, but the Content is not JSON.
@edossantos

So, what should I do to be Content Type is JSON at CFD?
I see only that entry point at Web Service Rest Component of CFD
 
@edossantos

I got it. API returns 204. I passed content type as json format.
Thank you so muchhh

1648048014859.png

1648048036318.png
 
  • Like
Reactions: edossantos
@edossantos

Let me close this post.
Thank you so much for your help.
 
  • Like
Reactions: edossantos
Status
Not open for further replies.

Forum statistics

Threads
112,322
Messages
591,889
Members
165,470
Latest member
Robert Lee