Looking for Examples of Consuming SugarOnDemand REST API

Looking for Examples of Consuming SugarOnDemand REST API

  
Hi All,

I am currently working on a project that requires me to consume a VARIETY of webservices from our SugarOnDemand database. I am however trying without luck to get it working and connected. 

I have a feeling it is something to do with the OAuthToken or the Authentication Credentials as I am returning 404 Not Found errors when I publish my application.

Does anyone have an examples or can offer any advice on this issue?

Help would be greatly appreciated.

Thanks
Tom
Hi Tom,

Can you share what you have so far? It's hard to help with soo little information...
From what I understood from SugarCRM's documentation you need to call login method before you call oauth_access to get a oauth2 access token.
Hi Tom,
 
I worked on it recently.
 
You have to authenticate with the OAuthToken:
 
1. POST http://<YOURSERVER>/sugarcrm/rest/v10/oauth2/token
Request:
{
"grant_type":"password",
"client_id":"<yourclient_id>",
"client_secret":"<yourclient_secret>",
"username":"<yourusername>",
"password":"<yourpassword>",
"platform":"base"
}
 
Response:
{
   "access_token": "b6a26cdd-d3e6-d997-ciii-545cf89c647b",
   "expires_in": 3600,
   "token_type": "bearer",
   "scope": null,
   "refresh_token": "b6de981f-52oa-743d-3969-545cf8c5ea92",
   "refresh_expires_in": 1209600,
   "download_token": "b781eyf0-7b6a-0242-f597-545cf8fuu4146"
}
Your user on SugarCRM must have User Type as 'Regular User'.
 
 
2. When you call a method (Ex: http://<YOURSERVER>/sugarcrm/rest/v10/Contacts) you have to pass the access_token you received on HTTP Header using property name 'oauth-token'.
 
Note: In your local variables, use 'Record' and 'RecordList' as Data Type. 
Don't use 'List' and <Entity> or <Structure> Data Types. I had problems with this.

Hope it helps you!

Regards,
Filipe Godinho
 
Hi Filipe,

Thanks a lot for your help. I have been able to return the token to a variable. However in order to get it to return the token value I needed to remove the Platform and Client Secret from the Request. Strange but it is working for now.

When I attempt to parse the variable into the header of the GET /<module> webservice it returns a 404 error.

This is the url that I am using:

https://<mycompany>.sugarondemand.com/rest/v10/opportunities?oauth-token={token}

Where token is the token variable from the POST Token webservice that is in the same screen flow.


Hi Tom,

Notice that Filipe said "HTTP Header" in your example you are sending the oauth-token in the URL and not an header.
Remove it from the URL and set it to send in Header and see if it works (also notice that you will have to set the Original Name since it has a "-")



Regards,
João Rosado

Thankyou so much for the help guys, I have been able to retrieve my information.

I am now trying to write a filter into my response as the option is available according to the API documentation. I want to apply a dynamic filter each time that filters the responses that have a 'date_closed' field after the current date. I am trying without luck to pass a filter into the url of the request. So far it has been as follows.

https://<MYSERVER>.sugarondemand.com/rest/v10/Opportunities?max_num=-1&filter=date_close$gt{date}

Where I parse the value of currdate() into the date variable.

The other option that i attempted was to filter the JSON using 

This throws an "unexpected curdate()" error.

{
   "filter":[
      {
         "date_closed":{
            "$gt":curdate()
         }
      }
   ]
}