Hello,
you can try the below PHP code for connection:
'client_credentials',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'resource' => 'https://your_d365_instance.crm.dynamics.com'
];
$url = "https://login.microsoftonline.com/$tenantId/oauth2/token";
// Use cURL to send the token request
$curl = curl_init();
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);
// Use the access token to make a request to the Web API
$headers = [
"Authorization: Bearer $accessToken",
"OData-MaxVersion: 4.0",
"OData-Version: 4.0",
"Accept: application/json",
"Content-Type: application/json; charset=utf-8"
];
$url = "https://your_d365_instance.crm.dynamics.com/api/data/v9.1/accounts";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
curl_close($curl);
echo $response;