Trouble with v8 API request to /api/oauth/access_token

Hi,

I’ve installed v7.10 on Windows and am having trouble trying to get an access token, I’m getting an error that an authorization header should be in the request, which isn’t necessary according to the documentation. I’m using Postman to perform the test.

I have added this URL rewrite rule to the web.config as hinted by the documentation:


<rule name="API" stopProcessing="true">
   <match url="api/(.*)" />
   <action type="Rewrite" url="lib/API/public/index.php" appendQueryString="true" />
</rule>

This is the request:


POST /api/oauth/access_token HTTP/1.1
Host: myhost.com
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
    "grant_type": "password",
    "client_id": "a0c90958-83e1-12d0-4aa7-5a92276379e4",
    "client_secret": "mysecret",
    "username": "myusername",
    "password": "mypassword",
    "scope": "basic"
}

This is the response:


{
    "error": "access_denied",
    "message": "The resource owner or authorization server denied the request.",
    "hint": "Missing \"Authorization\" header"
}

Any ideas on what the problem could be?

I think I’m one step closer, but getting another error.

Using this rewrite rule in the web.config seems to work better:


<rule name="api" stopProcessing="true">
    <match url="api/(.*)" />
    <action type="Rewrite" url="lib/api/public/index.php/{R:1}" />
</rule>

But now I get this error response that the password grant type isn’t supported:


{
    "error": "unsupported_grant_type",
    "message": "The authorization grant type is not supported by the authorization server.",
    "hint": "Check the `grant_type` parameter"
}

Almost there…

The request has to be sent using either the “form-data” or “x-www-form-encoded” option, not with the “raw” option, with each item as its own key/value pair.

But, now I’m getting an error in the response:


{
    "errors": [
        {
            "code": 1,
            "title": "Database failure. Please refer to suitecrm.log for details.",
            "status": 400
        }
    ],
    "meta": {
        "suiteapi": {
            "major": 8,
            "minor": 0,
            "patch": 0,
            "stability": "ALPHA"
        }
    },
    "jsonapi": {
        "version": "1.0"
    }
}

suitecrm.log shows this error (I’ve shortened the access_token and column name value for readability/security):


Mon Feb 26 22:03:53 2018 [10360][1][FATAL] Error running count query for OAuth2Tokens List:  Query Failed: SELECT count(*) c FROM oauth2tokens   LEFT JOIN  users jt0 ON oauth2tokens.modified_user_id=jt0.id AND jt0.deleted=0

 AND jt0.deleted=0  LEFT JOIN  users jt1 ON oauth2tokens.created_by=jt1.id AND jt1.deleted=0

 AND jt1.deleted=0 where (access_token = "f91c........b15f") AND oauth2tokens.deleted=0::: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid column name 'f91c........b15f'.
Mon Feb 26 22:03:53 2018 [10360][1][FATAL] [ERROR] Database failure. Please refer to suitecrm.log for details.

I guess this SQL query error is a bug?

I have since switched to using the Bitnami SuiteCRM stack, which doesn’t have this problem and uses MySQL.

Hi alanm,

Please consult the documentation:
https://docs.suitecrm.com/developer/api/version-8/configure-authentication/

Also I would recommend that you use the latest version SuiteCRM.

My suitecrm version is not latest,and I need to make the oauth authentication , their is no version 8 api there , how to do this?