hi,
i try to use the crm for a bigger project, so i have to test the api.
i decided to use the v8, because v4 is depricated.
the main problem is, i cant get the access token, if i add the default scopes from the example,
it the scope is empty, i get a token.
<?php
class apiRequest
{
protected $token = null;
protected $channel = null;
protected $host = "https://example";
protected $scope = null;
function __construct()
{
$this->channel = curl_init();
}
function setScope($scope)
{
$this->scope = $scope;
}
function getToken()
{
$params = array(
'grant_type' => 'client_credentials',
'client_id' => 'xxxxx',
'client_secret' => 'yyyyy',
'scope' => $this->scope
);
$url = '/Api/access_token';
$data = $this->request($url, $params, 'POST');
print_r($data);
if ($data) {
$this->token = $data->access_token;
} else {
echo "ERROR NO TOKEN\n";
}
}
function request($urlPath, $params, $method = 'GET')
{
$header = array(
'Content-type: application/vnd.api+json',
'Accept: application/vnd.api+json',
);
if ($this->token) {
$header[] = 'Authorization: Bearer ' . $this->token;
}
$postStr = json_encode($params);
curl_setopt($this->channel, CURLOPT_URL, $this->host . $urlPath);
curl_setopt($this->channel, CURLOPT_CUSTOMREQUEST, $method);
if ($method != 'GET') {
curl_setopt($this->channel, CURLOPT_POSTFIELDS, $postStr);
}
curl_setopt($this->channel, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->channel, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($this->channel);
$code = curl_getinfo($this->channel, CURLINFO_HTTP_CODE);
if ($code == 200) {
return json_decode($output);
} else {
print_r(json_decode($postStr));
print_r(json_decode($output));
}
return false;
}
}
$api = new apiRequest();
#'standard:create standard:read standard:update standard:delete standard:delete standard:relationship:create standard:relationship:read standard:relationship:update standard:relationship:delete'
$api->setScope('standard:create');
$api->getToken();
#/Api/V8/modules/Account/2
$url = "/Api/V8/module/Accounts";
$params = array('data' => array('attributes' =>
array('email_address' => 'email1@test.com',
'email_address_caps' => 'EMAIL1@TEST.COM',
'type' => 'EmailAddresses')));
$params = array();
#$ret = $api->request($url, $params, 'GET');
#print($ret);
return without scope:
[code]
stdClass Object
(
[token_type] => Bearer
[expires_in] => 3600
[access_token] => eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjNiMWE4Y2EwMWQ1YmNiMTEwZjJlNDMwM2Q0OWU1MDQwZDE1YTAwNDM0NDUyM2FhMTlmNDkxNDA1ZjEwZmZhMDk0YTczZTY3Yzk2Y2E2ZTkzIn0.eyJhdWQiOiJmMTAxZTVkMi1kMzJmLTZmMjAtZTNjOS01YzZiZGVmYmFkNjgiLCJqdGkiOiIzYjFhOGNhMDFkNWJjYjExMGYyZTQzMDNkNDllNTA0MGQxNWEwMDQzNDQ1MjNhYTE5ZjQ5MTQwNWYxMGZmYTA5NGE3M2U2N2M5NmNhNmU5MyIsImlhdCI6MTU1MDU5MDk1NiwibmJmIjoxNTUwNTkwOTU2LCJleHAiOjE1NTA1OTQ1NTYsInN1YiI6IiIsInNjb3BlcyI6W119.lJALhyK_hOZEP9iT4meFQG3i9ajisgUkncL6kSjkrKqjINFqTbMFdJ1O3-S9_-oMXbFOP0nxEalxEA7IqdxWhRXp9Ipk3uP094ZFYdxL3i4tTiNFWokBUHCpm6IdYkfWR1kxrzJ2RXyKlOJ-NtGdhVW9R9fHk6MSlYiQi8wv6ZAQ2T9GF29ekVTcGThEBACo9LWORYo8rzpKK1TTFmQsDoDIA78RKaJb4Ur8dwodPtZ6jmwMyUGZ6d8o_3FlD7hblM2FFm_x9xjji5Z_3tbykV2avgsU3RZ70Wg-sMyZf_VDX19GZBjVxMy9TcH5H3vR_4zrvJi9gdmBuGxWQzBIKQ
[/quote])
return with scope:
stdClass Object
(
[error] => invalid_scope
[message] => The requested scope is invalid, unknown, or malformed
[hint] => Check the `standard:create` scope
)
can someone help me to discover the problem?
thanks
onlyme