Menu
SuiteCRM Pull Request Party hosted by SalesAgility
Welcome, Guest
Username: Password: Remember me

TOPIC: SuiteCRM 7.11.1 api v8 scope problem

SuiteCRM 7.11.1 api v8 scope problem 3 months 12 hours ago #78045

  • onlyme
  • onlyme's Avatar
  • Offline
  • New Member
  • Posts: 1
  • Karma: 0
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:
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:
[code]
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
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 3 months 12 hours ago #78046

  • saad.achaaban
  • saad.achaaban's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
<?php

$ch = curl_init();
$header = array(
'Content-type: application/json',
'Accept: application/json' );
$postStr = json_encode(array(
'grant_type' => 'client_credentials',
'client_id' => 'xxxxxxxxxx'',
'client_secret' => 'xxxxxxxx',
'scope' => ''
));
$url = 'https://url/Api/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);


$tab = json_decode($output);

echo "<pre>";
print_r($tab->access_token);
echo "</pre>" ;

curl_close($ch);

I'm not using scope and it's work for me
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 3 months 12 hours ago #78047

  • helgebe
  • helgebe's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 5
  • Karma: 1
docs.suitecrm.com/developer/api/version-...api/#_authentication

Scopes

Scopes haven’t implemented yet

Best of luck!
I ended up using V41 after some fighting with attachments and email addresses and what not, and some short attempt on making custom api on V8.
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 3 months 12 hours ago #78049

  • saad.achaaban
  • saad.achaaban's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
I think i will do the same, 3 days already trying to custom version 8 and no concrete result
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78170

  • harendra
  • harendra's Avatar
  • Offline
  • Senior Member
  • Posts: 47
  • Karma: 0
Hi,

I was using old version of SuiteCRM and was updating the data on CRM using REST API V4.1

Recently I updated the SuiteCRM to 7.11.1 version and REST API V4.1 is stopped working for this now.

I will have to wriite the REST API code for V8 version.

Can anyone please let me know how can I get the values for "client_id" and "client_secret" to get the access token for existing running SuiteCRM 7.11.1

Thanks in advance for response.
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78172

  • helgebe
  • helgebe's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 5
  • Karma: 1
Admin - Oauth2 Clients and Tokens - New Client Credentials Client

and then the request could look something like this with php curl (CURLOPT_POSTFIELDS)
$oauth2_credentials = array(
'client_id' => $apikeyfromsuite,
'client_secret' => $yoursecret,
'grant_type' => 'client_credentials',
'scope' => '',

);
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78173

  • harendra
  • harendra's Avatar
  • Offline
  • Senior Member
  • Posts: 47
  • Karma: 0
Thanks for your quick reply.

Should the URL of CRM always starts with https:// ?
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78176

  • helgebe
  • helgebe's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 5
  • Karma: 1
It should, and I think it have to if you are going to use V8 API.
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78193

  • harendra
  • harendra's Avatar
  • Offline
  • Senior Member
  • Posts: 47
  • Karma: 0
My CRM is running on http://

Shall I not be able to use V8 API.
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78194

  • helgebe
  • helgebe's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 5
  • Karma: 1
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 months 4 weeks ago #78195

  • harendra
  • harendra's Avatar
  • Offline
  • Senior Member
  • Posts: 47
  • Karma: 0
Thanks
The administrator has disabled public write access.

SuiteCRM 7.11.1 api v8 scope problem 2 weeks 2 days ago #82790

  • harendra
  • harendra's Avatar
  • Offline
  • Senior Member
  • Posts: 47
  • Karma: 0
I want to upgrade my SuiteCRM to latest generation of SuiteCRM versions. Since I am using REST API4.1 for my existing SuiteCRM and came to know that I have to use API v8 for latest generation of SuiteCRM versions, I installed SuiteCRM 7.11.3 with dummy data on our demo server running on https with PHP version 7.1.17.

After this, I generated "client_id" and "client_secret" for "Client Credentials" Grant type by navigating at "Admin" - "OAuth2 Clients and Tokens" - "New Client Credentials Client" on this.

Now I am checking the CRM API for Authentication with Client Credentials and trying to obtain a session using below code but neither getting any array or session nor any error for this.

$ch = curl_init();
$header = array(
'Content-type: application/vnd.api+json',
'Accept: application/vnd.api+json',
);
$postStr = json_encode(array(
'grant_type' => 'client_credentials',
'client_id' => 'xxxxxxxxxx',
'client_secret' => 'xxxxxxxxxx'
));
$url = 'https://url/Api/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);

$tab = json_decode($output);
echo "<pre>"; print_r($tab); echo "</pre>" ;
curl_close($ch);

I have tried by adding "'scope' => ''" in $postStr as suggested in one of posts but did not return anything.

Can anyone please guide regarding this?

Thanks in advance.
The administrator has disabled public write access.
Time to create page: 0.046 seconds
Powered by Kunena Forum