Hello,
I have an install of SuiteCRM on Ubuntu 20.04. It’s SSL encrypted and has mod rewrite enabled and I have run composer install and created the necessary public and private key files as described here.
I am calling the version 8 API at /API/access_token with the following code:
<?php
$ch = curl_init();
$header = array(
// 'Content-type: application/vnd.api+json',
'Accept: application/vnd.api+json',
'Content-type: application/x-www-form-urlencoded',
);
$postStr = json_encode(array(
'grant_type' => 'client_credentials',
'client_id' => 'myclientid',
'client_secret' => 'myclientsecret',
));
$url = 'https://mydomain.com.au/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);
curl_setopt ($ch, CURLOPT_CAINFO, 'C:\Users\Me\Downloads\cacert.pem');
$output = curl_exec($ch);
var_dump($output);
$err = curl_error($ch);
var_dump($err);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpcode;
This is almost exactly the same as the script described in the documentation except that I’ve changed the content type header to be ‘Content-type: application/x-www-form-urlencoded’. I did this because with ‘Content-type: application/vnd.api+json’ it’s giving me a response code 404 Not Found.
The output from the script is this:
string(112) "{"grant_type":"client_credentials","client_id":"myclientid","client_secret":"myclientsecret"}"
string(0) ""
200
So I’m receiving a 200 response code and no errors, but the API is passing me back exactly the same thing that I am passing it in the body of the request. It should be giving me a bearer token like this from the documentation
{
"token_type":"Bearer",
"expires_in":3600,
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjdkOTEyODNhMjc1NDdkNDRlMzNmOTc5ZjVmMGRkYzQwNzg1ZGY5NGFhMWI5MDVlZGNmMzg3NWIxYjJkZDMzNDljZWEyNjZhMTQ2OTE5OWIzIn0.eyJhdWQiOiJzdWl0ZWNybV9jbGllbnQiLCJqdGkiOiI3ZDkxMjgzYTI3NTQ3ZDQ0ZTMzZjk3OWY1ZjBkZGM0MDc4NWRmOTRhYTFiOTA1ZWRjZjM4NzViMWIyZGQzMzQ5Y2VhMjY2YTE0NjkxOTliMyIsImlhdCI6MTUxODE5NTEwMiwibmJmIjoxNTE4MTk1MTAyLCJleHAiOjE1MTgxOTg3MDIsInN1YiI6IjEiLCJzY29wZXMiOltdfQ.EVGuRisoMxSIZut3IWtgOYISw8lEFSZgCWYCwseLEfOuPJ8lRMYL4OZxhu9gxJoGF0nj3yc6SYDPxovrsoj8bMoX38h4krMMOHFQLoizU0k2wAceOjZG1tWKPhID7KPT4TwoCXbb7MqAsYtVPExH4li7gSphJ8wvcWbFdS5em89Ndtwqq3faFtIq6bv1R4t0x98HHuT7sweHUJU40K9WQjbAfIOk8f5Y6T2wassN2wMCBB8CC6eUxLi14n2D6khHvkYvtPbXLHpXSHZWvEhqhvjAeSR5MmMrAth9WDSWUx7alO-ppsZpi8U7-g9Be5p6MRatc25voyTI2iTYbx02FQ",
}
One thing I have noticed in the suitecrm.log file is this debug message seemingly related to the API:
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/slim.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/controllers.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/factories.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/globals.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/helpers.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/middlewares.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/params.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/services.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/validators.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/services.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom file is not exists: custom/application/Ext/Api/V8/beanAliases.php
Wed Jun 21 10:15:53 2023 [452114][-none-][DEBUG] Custom routes file is not exists: custom/application/Ext/Api/V8/Config/routes.php
I have found a couple of github issues related to this but I can’t figure out what it’s about and also, my route is not a custom route so I don’t know if it is relevant.
Can anyone please help with why this is not working?
Cheers,
Clare