How to pass parameters into RESTlet using POSTMAN ?

I created a RESTlet that creates a customer record by taking two parameters as argument(customer_name & subsidiary). I want to call the RESTlet from POSTMAN. I want to know , how to pass the parameter which are required to run the RESTlet. You can refer the code to understand the requirement:

function RestletPost(data)
{
//create customer record
var customer = nlapiCreateRecord(‘customer’);

//set values of the record depending on the values submitted to the Restlet
if (data.isperson == false)
{
customer.setFieldValue(‘isperson’, ‘F’);
}
else
{
customer.setFieldValue(‘isperson’, ‘T’);
}
customer.setFieldValue(‘companyname’, data.companyname);
customer.setFieldValue(‘subsidiary’, data.subsidiary);

customer.setFieldValue(‘billpay’, ‘F’);

//submit record to NetSuite
var id = nlapiSubmitRecord(customer);

//create an object that would contain the response to be sent
var output = new Object();
output.id = id;

//send response back
return output;
}

Rookie Asked on April 15, 2020 in SuiteScript.
Add Comment
2 Answer(s)

Depending to the HTTP method that you use. If it is in GET, you have to append that mentioned parameter into the URL. If POST, depends on the Context-Type, but I would suggest that you use JSON so that you could just post the parameters as JSON on the request body

Rookie Answered on April 15, 2020.
Add Comment

One bit of advice is that if this is a brand new Restlet, you’d be well-advised to use the SuiteScript 2.0 API for this restlet script, rather than 1.0, as that API is deprecated.  There are some additional benefits of SS 2.0 as well,  particularly when working with checkbox fields, as you can actually set them with JavaScript boolean values: true/false, instead of ‘T’/’F’ that is required with SS 1.0.  You could then simply call

customer.setValue({ fieldId: 'isperson', value: data.isperson });

This looks like a POST request handler function, so the best approach is to set the Content-Type header to application/json, and then send a JSON string as your request body (set the radio button to raw).  The restlet engine will automatically map the JSON input to a JavaScript object (data). It would look something like this:

{
"companyname": "Company Name Here",
"subsidiary": 2,
"isperson": false
}

If you don’t set the Content-Type, the input will be treated as plain text, so you’d have to parse the data yourself before using it.

Beginner Answered on April 15, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor