1

I am working with dr chrono API and am trying to initialized the First step which is authorisation

The API documentation is here.

Here is an Authorisation sample:

https://drchrono.com/o/authorize/?redirect_uri=REDIRECT_URI_ENCODED&response_type=code&client_id=CLIENT_ID_ENCODED&scope=SCOPES_ENCODED

Here is what I have tried:

1.) I have tried the first code below

<?php

echo "<a href='https://drchrono.com/o/authorize/?redirect_uri=https://example_site.com/return_page.php&response_type=code&client_id=myclient-id-goeshere&scope=BASE_SCOPE:[read|write]'>Authorize</a>";


?>

but when the page redirects it displays error of Invalid_scope. Below is the error link returned.

https://example_site.com/return_page.php?error=invalid_scope

2.) Using Curl

$ci = 'my-client-id-goes-here';
$ci_encode = urlencode($ci);

$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'response_type'=>'code', 
    'client_id'=>$ci_encode,
    'redirect_uri'=>$uri_encode,
    'scope'=>'BASE_SCOPE:[read|write]',
]));
$response = curl_exec($ch);

curl_close($ch);

print_r($response);

Using curl code above does even redirect me at all.

I think the major problem is the scope not properly set. How can I solve this issue?

Update

Code section for curl:

$ci = 'my-client-id';
$ci_encode = urlencode($ci);
$uri = 'https://example_site.com/return_page.php';
$uri_encode = $uri;
$url = "https://drchrono.com/o/authorize/?";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'response_type'=>'code', 
    'client_id'=>$ci,
    'redirect_uri'=>$uri,
    'scope'=>'patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write'
]));
$response = curl_exec($ch);

curl_close($ch);

print_r($response);
Laurel
  • 5,965
  • 14
  • 31
  • 57
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38
  • the docs says the parameter "redirect_uri" must contains a URL-encoded . I think you should use php function `urlencode()` : 'redirect_uri'=>urlencode($uri_encode), – Shaolin Dec 17 '20 at 11:51

1 Answers1

1

Instead of BASE_SCOPE:[read|write] I would use patients:summary:read patients:summary:write calendar:read calendar:write clinical:read clinical:write

The docs say that you can choose among user, calendar, patients, patients:summary, billing, clinical and labs and compose a scope out of these values.

cssBlaster21895
  • 3,670
  • 20
  • 33
  • thanks for contributions so far. The link code option is now working with the scope but the curl code is not working. I have updated the scope in curl but when I run the code, on the next page it loads, it says **CSRF Failure** if I remove the back slash and question marker parameter in the API URL and then change the API URL to **https://drchrono.com/o/authorize** it will print 1 and will not redirect. Please can you see **Update code section for Curl** on the posts updates. Thanks – Nancy Moore Dec 17 '20 at 12:19
  • help me on this https://stackoverflow.com/questions/65359210/getting-error-with-curl-and-trellis-php-wordpress – BugsCreator Dec 18 '20 at 15:12