Hey there, I'm trying to test a restlet script and...
# suitescript
g
Hey there, I'm trying to test a restlet script and as part of the process, I'm expecting a transaction to be posted against the external url... the middleware system is posting a transaction and is getting a 200 ok response however cannot see the script being executed and if I look at the url.. I'm getting this error - error code: INVALID_RETURN_DATA_FORMAT error message: {"type":"error.SuiteScriptError","name":"INVALID_RETURN_DATA_FORMAT","message":"Invalid data format. You should return text.","stack":["createError(N/error)"],"cause":{"name":"INVALID_RETURN_DATA_FORMAT","message":"Invalid data format. You should return text."},"id":"","notifyOff":false,"userFacing":true} any ideas?
s
Assuming you are returning JSON, the calling client should be using the
Content-Type
header set to:
application/json
👍 1
Otherwise, Netsuite assumes you will be using strings for input and output.
if the client can’t set that header, then a workaround is to call JSON.stringify on the JS object yourself and return the resulting string instead.
g
thanks @scottvonduhn my content-type is set to application/json... I'm thinking there must be something wrong with the script and now I can see it's executing however giving me the error of {"type":"error.SuiteScriptError","name":"INVALID_RETURN_DATA_FORMAT","message":"Invalid data format. You should return text.","stack":["createError(N/error)"],"cause":{"name":"INVALID_RETURN_DATA_FORMAT","message":"Invalid data format. You should return text."},"id":"","notifyOff":false,"userFacing":true}
s
what are you returning at the end of your entry point function?
b
INVALID_RETURN_DATA_FORMAT
means that the client is screwing up the content type header
g
thanks @battk but the content-type is application/Json? Is there something fundamentally wrong with the script? i.e. what should the doget function be doing?
b
the type that you return should match the content type
the error you are getting is what happens when they dont match
s
As stated, that error only comes from a mismatch between the content type and what the script is returning. As a test, try returning any string, even just "test". If the error goes away, then the calling client not sending the header correctly. Also, test the restlet from another tool, like postman or curl, to see if the error goes away.
g
okay thanks, trying to do a post request via postman - have you got an example of what the URL should look like? fyi - doing token based authentication...and what do I need to pass as part of the header?
b
you are hiding the information necessary to debug, but i would guess the realm
👍 1
r
realm gets me every time
s
Realm is the one thing Netsuite requires that isn’t commonly used in most other OAuth 1.0 situations. Though, now with the account-specific URL’s, you’d think it wouldn’t be needed anymore. They probably just don’t want to change their code 🙂
g
Think I've exhausted all options to figure this out? Still not sure why the fulfillment isn't being created even though I'm passing the information needed as per the script... Last call if anyone can help? @battk @scottvonduhn @reptar apreciate it
r
@G did you save it
1
b
you havent gotten very far in debugging
a quick glance suggests that something goes wrong within the first 20 lines of your post function
which your logs actually tell you
g
@battk I'm assuming you are talking about the length being undefined error within
doPost
? But isn't the defined in the script,
requestBody.length
- used to determine the number of items in an array no?
b
what does the code expect the requestBody to be
g
So if the Content-Type is 'text/plain' then the 'requestbody' will be passed as a string and if application/Json then it requires for it to be a valid Json...
b
that is something that you will have to worry about
but thats not really where your problem is at
the requestBody is one of the inputs to your entry point function
and as written, it expects a certain data type
you will need to determine what that is to really go much further
okay
going from what you are saying
if requestBody is supposed to be an object specifically
Copy code
var requestBody = {
    "customform": "141",
    "trandate": "2023-03-03T14:00:46.000-04:00",
    "shipstatus": "C",
    "internalid": "68780607",
    "ExternalId": "321123231",
    "linesToFulfill": [
        {
            "orderLine": "1",
            "quantity": "1"
        }
    ]
}
then
Copy code
var intSalesOrderCount = requestBody.length;
is always supposed to be undefined
g
hmm, got a 400 bad request
g
getting error - {"type":"error.SuiteScriptError","name":"USER_ERROR","message":"You must enter at least one line item for this transaction.","stack":["anonymous(N/serverRecordService)","doPost(/SuiteScripts/Eve_rs_fulfilsalesorder_new2.js:361)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"You must enter at least one line item for this transaction.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","doPost(/SuiteScripts/Eve_rs_fulfilsalesorder_new2.js:361)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false} What I'm passing through and what is on the sales order lines is: [ { "customForm": "98", "tranDate": "01/03/2023", "status": "A", "DispatchID": "1234", "salesOrderId": "68780607", "linesToFulfill": [ { "lineId": "1", "item": "232 Natural", "quantity": 1 }, { "lineId": "13", "item": "232 Natural", "quantity": 2 } ] }, { "customForm": "98", "tranDate": "01/03/2023", "status": "A", "DispatchID": "5678", "salesOrderId": "68762641", "linesToFulfill": [ { "lineId": "1", "item": "232 Natural", "quantity": 1 }, { "lineId": "18", "item": "232 Natural", "quantity": 2 }, ] } ]
so why would this error happen?
and if I remove the
"item": "",
line, I get the error org.mozilla.javascript.EcmaError: SyntaxError: Unexpected token in object literal (INVOCATION_WRAPPER$sys#24)? can I get some actual help rather than just another link to look at?
b
my personal suspicion is that this isnt your script and you dont know how to maintain it
so you either learn how to do so or fail in your task so someone else can try
😁 1
you didnt know what a 400 status error is, nor that by itself it offers no information
its the generic error you get when an error is thrown
you have now provided the error, so now actual help can be given
in this case there are no items to be fulfilled on the item fulfillment you are creating
there are multiple reasons that the error can occur, the two likely guesses are that you are using the wrong inventory location or that you arent marking the item receive checkbox on the fulfillment lines
it could be something else, so my general recommendation is to learn how to create the fulfillments you want using your own code and then make sure the restlet is doing the same actions
👍 1
the restlet is using dynamic mode, so you will have to know how to create the fulfillment in the ui and pay attention to the order in which those fields are set