web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archive)
Suggested answer

WebAPI Access Token

(0) ShareShare
ReportReport
Posted on by 80

HI 

I have successfully connected D365 WebAPI with Postman but every time I GET or POST something , I need to regenerate access token and use that new token . Is there any way I use only one token and not need to recreate it ?

Second question is , How I can use WebAPI on my website to send data from my website(json , php) to D365 ? As I need to recreate access token every time , I can not use access token . Is there anyway I can use only API key or clientid and client secrete key for connection ?

Thanks

Hemisha

  • Naveen Ganeshe Profile Picture
    3,392 Moderator on at
    RE: WebAPI Access Token

    Good to hear that

  • HGajjar Profile Picture
    80 on at
    RE: WebAPI Access Token

    HI

    I have solved the issues . It was silly php syntax issues .

    'Authorization: Bearer '.$accessToken   instead of     'Authorization: Bearer $accessToken'

    Thank you all for help .

    Thanks

    Hemisha

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,392 Moderator on at
    RE: WebAPI Access Token

    Hi Hemisha,

    Please take a look at these git repo. They are also using similar kind of integration: github.com/.../php-crm-toolkit

    github.com/.../dynamics-sdk-php

    You can find the code in src folder.

  • HGajjar Profile Picture
    80 on at
    RE: WebAPI Access Token

    Hi

    I have created new user and then it was working fine. But but when I try to create account using bellow code , I am getting error . Same thing working fine in postman .

    I am getting 

    {"error":{"code":"0x80048d19","message":"Error identified in Payload provided by the user for Entity :'accounts'

    my code :

    $curl = curl_init();
    $clientId = "xxxxxxxx";
    $clientSecret = "xxxxxxx";
    $tenantId = "xxxxxxx";

    // Build the body for the token request
    $body = [
    'grant_type' => 'client_credentials',
    'client_id' => $clientId,
    'client_secret' => $clientSecret,
    'resource' => 'https://xxxx.dynamics.com'
    ];

    $url = "">login.microsoftonline.com/.../token";
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($curl);
    $response = json_decode($response);
    $accessToken = $response->access_token;


    curl_close($curl);

    $headers = [
    "Authorization: Bearer ".$accessToken,
    "OData-MaxVersion: 4.0",
    "OData-Version: 4.0",
    "Accept: application/json",
    "Content-Type: application/json; charset=utf-8"
    ];

    $body1 = [

    'name' => 'testtest'

    ];

    $url = "">xxxxxx/.../accounts";
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body1));

    $response = curl_exec($curl);
    curl_close($curl);

    Any one suggest me why ?

    Thanks

    Hemisha

  • Suggested answer
    Bipin D365 Profile Picture
    28,958 Moderator on at
    RE: WebAPI Access Token

    Hi,

    Check if you have enabled security group for your Environment, if yes then make sure your user is part of this security group

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,392 Moderator on at
    RE: WebAPI Access Token

    Please check if the application user has the correct rights.

    docs.metallic.io/.../136228_register_dynamics_365_application_with_azure.html

    Please check point 14 in this: www.c-sharpcorner.com/.../

    monitoringguys.com/.../

  • HGajjar Profile Picture
    80 on at
    RE: WebAPI Access Token

    Hi

    I am the admin of the organization but still getting same error .

  • Suggested answer
    Amit Katariya007 Profile Picture
    5,769 Moderator on at
    RE: WebAPI Access Token

    Check if the user have appropriate roles in Dynamics 365 environment?

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,392 Moderator on at
    RE: WebAPI Access Token

    Please check if the user has appropriate rights. Also you have an application user in D365

  • HGajjar Profile Picture
    80 on at
    RE: WebAPI Access Token

    Hi

    Thank you for your code . Now I am getting bellow error

    : {"error":{"code":"0x80072560","message":"The user is not a member of the organization."}}

    I did check all setting . User is the member of organization. Dont know what else I need to set .

    Thanks

    Hemisha

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard > 🔒Ι Microsoft Dynamics CRM (Archived)

Featured topics

Product updates

Dynamics 365 release plans