I have attached a functioning GET and POST API, but I don't know how to view the json arguments sent to the API.
Example:the 'value': 'something to test' string. How do I get to that value in the API?.
I have attached a functioning GET and POST API, but I don't know how to view the json arguments sent to the API.
Example:the 'value': 'something to test' string. How do I get to that value in the API?.
Hi Amy,
All JSON parameters are available as part of your $args
variable in your API method argument.
This method will require the parameters $api
and $args
. Any path variables, query string parameters or posted data will be available in the $args parameter for you to work with.
From documentation: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.2/Integration/Web_Services/REST_API/Extending_Endpoints/
So if you pass {'value':'something to test'}
, you will be able to access it like $args['value']
The result I get from the following is 'Hello World'. I don't get anything from value.
Am I missing something?
I am using the following API:
I think the problem lies in Javascript.
SugarCRM uses CRUD approach for api calls, so you should not use POST/PUT/GET etc manually. You have to use create/read/update/delete.
Eg:
app.api.call('read', ... // GET
app.api.call('create', ... // POST
app.api.call('update', ... // PUT
Anything that is not CRUD is considered GET, so your JSON is never sent to backend, which is why you didn't see the value in your API. If you change it to create, it should do a POST and you should be able to see the value in $args.
I've tried to document some common snippets and usages here, in case it helps: https://seventunes.com/sugarcrm-javascript-snippets-1/#crud