Page 1 of 1

REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Mon May 08, 2017 2:44 pm
by pwaller24
I am trying to connect to ProcessMaker using REST API calls via Ruby. I can generate the appropriate requests and test those requests via the Advanced Rest Client. I am using a call to OAuth to get a token that will be used to access data in the database. Whenever I post it get :

"error":"invalid_request","error_description":"The grant type was not specified in the request"

Re: REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Mon May 08, 2017 5:52 pm
by amosbatto
You are not setting your grant_type or scope correctly when obtaining your access token. You need to send this information to obtain the token:
Code: Select all
{
    "grant_type": "password",
    "scope": "*",      
    "client_id": "XXXXXXXXXXXXXXXXXXXXXXX",
    "client_secret": "XXXXXXXXXXXXXXXXXXXXXX",
    "username": "jdoe",
    "password": "p4sSw0rd"
}

Re: REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Mon May 08, 2017 6:12 pm
by pwaller24
This is the body of the post:

{"grant_type":"password","scope":"*","client_id":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","client_secret":"YYYYYYYYYYYYYYYYYYYYYYYYY","username":"admin","password":"admin"}

Using this same data in the Advanced REST Client is successful. Perhaps it is an issue with how Ruby is formating the post data.

Re: REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Mon May 08, 2017 6:43 pm
by amosbatto
You need to set your content-type to application/json in the header when requesting the access token and you need to send the request as POST.

Re: REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Wed May 10, 2017 5:35 pm
by pwaller24
Here is the information from debugging my calls to the OAuth page:

[2017-05-10 21:22:42.165] DEBUG Sending post request to http://XX.XX.XXX.XXX:8080/workflow/oauth2/token with body: {"grant_type":"password","scope":"*","client_id":"ORFAVREOUWRAUGGRQJGTNKDRHKBSETWT","client_secret":"434157704590a695188bf57026369405","username":"pwaller","password":"welcome"} and headers:
http://52.39.212.230:8080/workflow/oauth2/token

{"grant_type":"password","scope":"*","client_id":"ORFAVREOUWRAUGGRQJGTNKDRHKBSETWT","client_secret":"434157704590a695188bf57026369405","username":"pwaller","password":"welcome"}
[2017-05-10 21:22:42.303] INFO POST http://52.39.212.230:8080/workflow/oauth2/token -- (0.13s) 400 {"error":"invalid_client","error_description":"The client credentials are invalid"} {"date"=>"Wed, 10 May 2017 21:22:42 GMT", "server"=>"Apache/2.4.6 (CentOS) PHP/5.4.16", "x-powered-by"=>"PHP/5.4.16", "access-control-allow-origin"=>"*", "vary"=>"Accept", "cache-control"=>"no-store", "content-length"=>"83", "connection"=>"close", "content-type"=>"application/json"}

It appears to me that the content-type is set to application/json and the body is valid json, includes the grant_type. The user id and password are valid and can log into ProcessMaker. The user is an Administrator.

Any ideas would be appreciated.

Re: REST API Calls to ProcessMaker vis Ruby on Rails

Posted: Wed May 10, 2017 8:25 pm
by amosbatto
I have no clue why it isn't working. You might try using another library, like this one:
https://github.com/rest-client/rest-cli ... /README.md

According to its README.md file, you can use this:
Code: Select all
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}