i am starting to learn restlets and am using insom...
# suitetalkapi
p
i am starting to learn restlets and am using insomnia to test. was able to get a reply back but the formatting of the data is not what i was expecting. I am getting the following:
{\"id\":\"64458\",\"type\":\"salesorder\",\"isDynamic\":false,\"fields\":
but was expecting something like this:
Copy code
{
 "id": "64458"
 "type": "salesorder"
 "isDynamic": false
 "fields": {
is this an insomnia thing or am i doing something wrong. My code does contain the following:
"Content-Type: application/json"
b
probably wrong channel to ask, #C29HQS63G is what you want
that said, the answer to this question will depend on which suitescript version your restlet is using
this is one of those things that differ between suitescript 2.1 and 2.0
general cause is that you are not setting the correct content type
p
thanks. it's 2.0 and based on what you linked it is doing what it is supposed to.
b
general idea is to return an object from the restlet if you want a json object
return a string if you want a json string
z
could you share your return statement in RESTLet? Usually, I have simple : return({...object...})
p
I'm just using the example from the help section:
Copy code
function _get(context) {
            doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'GET');
            return JSON.stringify(record.load({
                type: context.recordtype,
                id: context.id
            }));
        }
z
JSON.stringify() convert object {...} into string "{...}". That's why response is string .... Just try without JSON.stringify
Copy code
var response = record.load(...);
return response
Copy code
function doGet(requestParams) {

            var _type = requestParams.type;
            var _id = requestParams.id;

            var _rec = recordModule.load({
                type : _type,
                id : _id
            })

            return _rec;
        }
I use this function in my RESTlet for getting one record of any record type