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

TOPIC: request to api return 404 error

request to api return 404 error 5 months 4 days ago #76294

  • GSSOCIAL
  • GSSOCIAL's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
Im running SuiteCRM-7.10.11 on virtual server over HTTPS. When I trying post to hostname/crm/api/oauth2/access_token i receive 404 error.

.htaccess checked:
<IfModule mod_rewrite.c>
    Options +SymLinksIfOwnerMatch
    RewriteEngine On
    RewriteBase /c
    RewriteRule ^cache/jsLanguage/(.._..).js$ index.php?entryPoint=jslang&modulename=app_strings&lang=$1 [L,QSA]
    RewriteRule ^cache/jsLanguage/(\w*)/(.._..).js$ index.php?entryPoint=jslang&modulename=$1&lang=$2 [L,QSA]
    
    # --------- DEPRECATED --------
    RewriteRule ^api/(.*?)$ lib/API/public/index.php/$1 [L]
    RewriteRule ^api/(.*)$ - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    # -----------------------------
    
    RewriteRule ^Api/access_token$ Api/index.php/access_token [L]
    RewriteRule ^Api/V8/(.*?)$ Api/index.php/V8/$1 [L]
    RewriteRule ^Api/(.*)$ - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Any advice? Thanks.
The administrator has disabled public write access.

request to api return 404 error 5 months 4 days ago #76319

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
I have seen several posts with this same problem. None seem to have been resolved. A couple that did get their issue resolved (different issues but might be relevant) seemed to be using /api/oauth/access_token as an endpoint. I am still not sure if it is supposed to be 192.168.XXX.XXX/api/oauth/access_token or 192.168.XXX.XXX/SuiteCRM/api/oauth/access_token but notice that both are "oauth" not "oauth2" so at least you might want to give that a try.

But like other posters I have other variations based on the directory structure like ...Api/V8, ...API/Oauth2 and some others but with no luck. I get a 404 not found error with all of them.

Can anybody please just clarify what the correct endpoint is?

Thanks a lot!
The administrator has disabled public write access.

request to api return 404 error 5 months 3 days ago #76337

  • GSSOCIAL
  • GSSOCIAL's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
UPD: Noticied some errors in official (docs).

Code to make request via curl in documentation:
$ch = curl_init();
$header = array(
    'Content-type: application/vnd.api+json',
    'Accept: application/vnd.api+json',` //SYNTAX 1
 );
$postStr = json_encode(array(
    'grant_type' => 'client_credentials',
    'client_id' => '3D7f3fda97-d8e2-b9ad-eb89-5a2fe9b07650',
    'client_secret' => 'client_secret',
    'scope' => 'standard:create standard:read standard:update standard:delete standard:delete standard:relationship:create standard:relationship:read standard:relationship:update standard:relationship:delete'
));
$url = 'https://path-to-instance/api/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, url); //SYNTAX 2
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);

As u can see, we have 2 errors:
1) Line 4 - Symbol "`" at end - 'Accept: application/vnd.api+json',`
2) variale "url" wrote without "$" - curl_setopt($ch, CURLOPT_URL, url)


When I rewrite to code above I have new 404 error :cheer:
"The requested URL /crm/lib/API/public/index.php/oauth/access_token was not found on this server."
$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' => '3D7f3fda97-d8e2-b9ad-eb89-5a2fe9b07650',
    'client_secret' => 'client_secret',
    'scope' => 'standard:create standard:read standard:update standard:delete standard:delete standard:relationship:create standard:relationship:read standard:relationship:update standard:relationship:delete'
));
$url = 'https://luckwheel.ru/crm/api/oauth/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);
Last Edit: 5 months 3 days ago by GSSOCIAL.
The administrator has disabled public write access.

request to api return 404 error 5 months 3 hours ago #76474

  • alanm
  • alanm's Avatar
  • Offline
  • New Member
  • Posts: 15
  • Thank you received: 3
  • Karma: 0
This URL format works for me:
{{suitecrm.url}}/Api/access_token

Note that the Api portion of the URL is case sensitive, using a lowercase api returns a 404.
The administrator has disabled public write access.

request to api return 404 error 4 months 4 weeks ago #76508

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
Thank you alanm but that still doesn't work for me. It is so frustrating that at least in this forum the number of people that say they can not access the V8 API far exceeds the number of people who seem to have gotten it but there does not seem to any specific or definitive endpoint that works.

This url that worked for you is completely different than what the other posters said they were able to get in with.

I can only guess how many people are spending hours trying every variation of Api, API, api, etc hoping something will work and getting nowhere. I never had any similar issues with v 4_1 and I'm not sure why this should be such a mystery or such a difficult question to answer.

Thank you though for letting us know what worked for you. Maybe that will work for somebody else as well.
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76671

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
Has anybody had any luck with the V8 API? I saw a couple of posts that seemed to imply people were using it successfully but there are lot more posts of people getting the 404 error. Can anybody that has been successful just post the url they are using. A bunch of us are spinning our wheels here.

Thanks a lot.
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76674

  • alanm
  • alanm's Avatar
  • Offline
  • New Member
  • Posts: 15
  • Thank you received: 3
  • Karma: 0
What request are you trying to perform that isn't working? Please provide the exact URL you're using.
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76680

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
So far I am just trying to authenticate. I haven't even got to posting a request yet.
I can access the web interface through XXX.XXX.XXX.XXX/SuiteCRM and XXX.XXX.XXX.XXX/SuiteCRM
These are all POST requests:
XXX.XXX.XXX.XXX/SuiteCRM/Api/OAuth2/acce...X&client_secret=XXXX
XXX.XXX.XXX.XXX/SuiteCRM/Api/oauth/acces...X&client_secret=XXXX
XXX.XXX.XXX.XXX/SuiteCRM/oauth/access_to...X&client_secret=XXXX
XXX.XXX.XXX.XXX/SuiteCRM/Oauth2/access_t...X&client_secret=XXXX
XXX.XXX.XXX.XXX/SuiteCRM/Api/access_toke...X&client_secret=XXXX

I think I have tried over a hundred variations of API Api api oauth OAuth2 but they all seem to come up with a 404.

Thanks!
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76681

  • alanm
  • alanm's Avatar
  • Offline
  • New Member
  • Posts: 15
  • Thank you received: 3
  • Karma: 0
The authentication parameters need to be in the request body. Here is an example using cURL:
curl --request POST \
  --url http://127.0.0.1/suitecrm/Api/access_token \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data 'grant_type=client_credentials&client_id=5d0c0c67-6bac-8f69-3f74-5c43fe8c271e&client_secret=secret'
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76693

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
I copied your request exactly, changed my client_id and credentials and used 127.0.0.1 right in the terminal but still get a 404.
Just to make sure it wasn't some kind of access issue I also tried curl --request GET --url http://127.0.0.1/SuiteCRM/LICENSE.txt and that worked fine

s@s:~$ curl --request POST \
> --url http://127.0.0.1/SuiteCRM/Api/access_token \
> --header 'Content-Type: application/x-www-form-urlencoded' \
> --data 'grant_type=client_credentials&client_id=90f2061a-3f67-f28f-e905-5c32495a9f75e&client_secret=green'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /SuiteCRM/Api/access_token was not found on this server.</p>
<hr>
<address>Apache/2.4.29 (Ubuntu) Server at 127.0.0.1 Port 80</address>
</body></html>
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76702

  • alanm
  • alanm's Avatar
  • Offline
  • New Member
  • Posts: 15
  • Thank you received: 3
  • Karma: 0
What version number of SuiteCRM are you using?
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76710

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
Version 7.10.11
The administrator has disabled public write access.

request to api return 404 error 4 months 3 weeks ago #76711

  • alanm
  • alanm's Avatar
  • Offline
  • New Member
  • Posts: 15
  • Thank you received: 3
  • Karma: 0
I'm thinking the mod_rewrite Apache module isn't enabled. Here are some stack overflow posts that you can refer to test if it is:

stackoverflow.com/a/10891317/4797690
stackoverflow.com/a/27589801/4797690
The administrator has disabled public write access.
The following user(s) said Thank You: steveS

request to api return 404 error 4 months 3 weeks ago #76786

  • dsclee1
  • dsclee1's Avatar
  • Offline
  • New Member
  • Posts: 4
  • Thank you received: 2
  • Karma: 0
Hi, I'm a new user of SuiteCRM, and spent a few hours yesterday with exactly the same problem. I'm using 7.11.0, but assume it's the same set up as 7.10.11 for the API.

I tracked my issue down, and it was due to Rewriting being turned off (as expected), however not because mod_rewrite was disabled but because the image I'm using (a docker image from bitnami) disables rewriting by default in the apache config files.

"AllowOverride None" needs to be "AllowOverride All" for the .htacess file to function.

The documentation on which URLs are the correct ones for the V8 API isn't great. The latest docs look to be here: https://deploy-preview-90--suitedocs.netlify.com/developer/api/version-8/json-api-new/ but aren't quite correct as they omit the use of "/Api/" in the path I.E. it's "/Api/V8/module" not just "/V8/module".

I found the access_token URL is: http://mysite/Api/access_token
then if you actually want to do anything once you have the access token you have to parse the token into the header request of the module you'd like to call, with a base url of: http://mysite/Api/V8/module/

Here's an example in PHP that I've been playing with that pulls a list of all accounts:
$token_url = 'http://mysite/Api/access_token';
$module_url = 'http://mysite/Api/V8/module/';
$client_id = '12345678-1234-1234-1234-1234512345';
$client_secret = 'its a secret';
$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' => $client_id,
    'client_secret' => $client_secret
));
curl_setopt($ch, CURLOPT_URL, $token_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);
$out = json_decode($output,true);

$ch = curl_init();
$header = array(
    'Content-type: application/vnd.api+json',
    'Accept: application/vnd.api+json',
    'authorization: Bearer '.$out["access_token"]
 );
$item = 'Accounts?sort=-name';
curl_setopt($ch, CURLOPT_URL, $module_url . $item);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);
echo $output;

I now have another issue to do with permissions, but I'll make it a new post.
The administrator has disabled public write access.
The following user(s) said Thank You: steveS, kwongy

request to api return 404 error 4 months 3 weeks ago #76857

  • steveS
  • steveS's Avatar
  • Offline
  • Junior Member
  • Posts: 21
  • Karma: 0
Thank you all. alanm you were spot on.

I am using a generic Ubuntu 18.04LTS install on VirtualBox and it was not enabled. I did finally manage to get a response but there was a little more to it so I will add a few things that I had to do for those experiencing the same thing or those new to ssl as I am.

sudo a2enmod rewrite sudo systemctl restart apache2 to enable mod_rewrite

edit /etc/apache2/apache2.conf and add:
<Directory /var/www/html/SuiteCRM>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

I also created a SuiteCRM.conf file but I don't think I actually had to do that.

Thanks again.everyone. I too haven't gone past the authentication yet but that has been stumping me for a while now so I really appreciate the help.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.043 seconds
Powered by Kunena Forum