jsonnetsuiteposter

Put not working using Poster


I am most likely doing something wrong but not sure what. I am trying to test a NetSuite Restlet (web service) using FF poster. I can use Get to work by passing data in the URL. However, I get an error using the Put method.

{"error" : {"code" : "SYNTAX_ERROR", "message" : "SyntaxError: Empty JSON string (null$lib#3)."}}

It's hitting my catch block below. I read that to create or update we should use Put so not sure why Get works but not Put?

function CreateRecord(jsonobject)
{
    try
    {
        nlapiLogExecution('DEBUG', '  in get =  ');

        var jsonString = JSON.stringify(jsonobject)
        nlapiLogExecution('ERROR', 'JSON', jsonString);

        // Mandatory
        var name = jsonobject["name"];
        nlapiLogExecution('DEBUG', '  name =  ', name);

        var record = nlapiCreateRecord('customrecordtest');
        record.setFieldValue('name', name);
        var id = nlapiSubmitRecord(record, true);
        nlapiLogExecution('DEBUG', 'id  =  ', id);
        return jsonobject;
    }
    catch (err) 
    {
        nlapiLogExecution('ERROR', 'Error', err.message);       
        return err.message;
    } 
}

Poster:

https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=351&deploy=1&name=Restlet Test


Solution

  • A PUT request will not look for data in the URL. It will look for JSON in the body of the request itself. So instead of &name=Restlet Test, you will need to send an object in the body of the request like { "name" : "Restlet Test" }