One of our customer want to connect to us using AP...
# suitescript
s
One of our customer want to connect to us using API. I created a restlet and ask them to set the params like this and the body { "Invoice": "", "shipto": { "name": ", "addr1": "", "city": "", "state": "", "zip": "", "phone": "", "email": "" }, There will be multiple entry in the JSON In the restlet, how can I access the parameters ?
m
Edit: Give me a moment, I was giving you code for getting body data... I'll get you paramater data in a second
👍 1
@Simon Okay, looks like I was correct before (I think). It's accessed via the in_data parameter (the first and only parameter of the function). However, for POST and PUT, it looks like it is the body data instead. So it acts differently for GET and DELETE than it does for PUT and POST (data URL paramater versus body of the request)
So I'm pretty sure you could just access it with function called_get(in_data){nlapiLogExeuction('debug', 'this is my paramaters object', in_data);}
And in_data would be the object you specified above
However, personally, I would recommend they send the data via a POST request - in which case they would send the data via the body of the request instead of in the URL paramaters.
Either way I think you access it the same though
I might be wrong on this though... haven't personally tested it out, this is just how it looks in documentation.
(it doesn't give a direct example, but references it)
If you are using SS2, I'd assume it would be the same.
Just looked. In SS2, GET parameters are available via requestParams (the first object passed into your get function), whereas POST body is available via requestBody (also the first object passed into your get function). So pretty much the same.
One last note - using RESTlet's is great because it's quite secure, but if for some reason your client can't get the OAuth implementation working (OAuth is a bit of a pain sometime), you can technically roll your own via a publicly accessible Suitelet, where people are able to just use a key to access things. You should be very careful to wrap everything in a try-catch block though - you don't want to leak things to a customer in an error message, which is more likely when you do an approach like this. It is a ton simpler overall though.