# Get token for Rest API

**URL:** <https://forums.concretecms.org/t/get-token-for-rest-api/4460>\
**Category:** Developing with Concrete\
**Created:** [November 15, 2022, 12:42pm UTC](https://forums.concretecms.org/t/get-token-for-rest-api/4460 "2022-11-15T12:42:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![katalysis](https://forums.concretecms.org/user_avatar/forums.concretecms.org/katalysis/32/5562_2.png) [@katalysis](https://forums.concretecms.org/u/katalysis)\
**Post date:** [November 15, 2022, 12:42pm UTC](https://forums.concretecms.org/t/get-token-for-rest-api/4460/1 "2022-11-15T12:42:26Z")

</div>

I’m trying to use the rest API to bring data from an external Concrete CMS site in using PHP.

I’m using the following code to try and get a token:

```auto
$authurl = "https://www.katalysis.net/oauth/2.0/token";

$client_id = $site->getApiClientId();
$client_secret = $site->getApiClientSecret();

 // Creating base 64 encoded authkey
$Auth_Key = $client_id.":".$client_secret;
$encoded_Auth_Key=base64_encode($Auth_Key);

$headers = array();
$headers['Authorization'] = "Basic ".$encoded_Auth_Key;
$headers['Content-Type'] = "application/x-www-form-urlencoded";

$data = array(
    'grant_type' => 'client_credentials',
    'scope' => 'system:info:read',
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $authurl);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_VERBOSE, '1L');
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

$auth = curl_exec( $ch );

if ( curl_errno( $ch ) ){
    echo 'Error: ' . curl_error( $ch );
}
curl_close($ch);

$secret = json_decode($auth);
$access_key = $secret->access_token;

print_r($secret);

```

This is returning the error:

stdClass Object ( [error] =\> invalid\_request [error\_description] =\> The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. [hint] =\> Check the `client_id` parameter [message] =\> The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. )

Any idea what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![katalysis](https://forums.concretecms.org/user_avatar/forums.concretecms.org/katalysis/32/5562_2.png) [@katalysis](https://forums.concretecms.org/u/katalysis)\
**Post date:** [November 15, 2022, 1:37pm UTC](https://forums.concretecms.org/t/get-token-for-rest-api/4460/2 "2022-11-15T13:37:27Z")

</div>

Solved this one - needed this:

```auto
 $data = array(
     'client_id' => 'ID',
     'client_secret' => 'SECRET',
     'grant_type' => 'client_credentials',
     'scope' => 'system:info:read',
);

```
