Hello Everyone, Here facing an issue with Usereve...
# suitescript
p
Hello Everyone, Here facing an issue with Usereventscript which is deployed on the Project master and the system is trying to call 3rd party URL in Usereventscript when the project master is updated in the rest API. Is any one faced same issue , could you please help us with resoloution. Below is an error message. { errors: [ { message: "Error connecting to database" } ] }
c
Are you saying that error is coming from the 3rd party URL?
p
It's coming from NetSuite. the URL is working fine on the UES script when the project master is updated through SCH script or UI modification on the Project master. It's not working when restapi is calling the UES script.
b
which line of code is throwing the error
p
Copy code
https.put
b
that implies the error is not actually from netsuite
its from your third party
c
Might be a good idea to familiarise yourself with tools like Postman
b
you also want to be very precise about how/what is happening with the error
an error that is thrown from https.put is very different than an error written in the body of the response of https.put
p
the concern here is the URL https.put is working when we manually update the project and UES is able to call 3 rd part url. but it's not working on rest api when we tried to call on the project update
b
thats more comparing the parameters from a successful request to your failed request
c
Share your code then. Impossible to help you at the moment
p
function get_JWT_token() { //************************Token Generation steps*****************************// var commonHeader = { "Content-Type": "application/json", "accept": "application/json" }; var tokenURL = 'https://XXXXXX/get_NS_tokens'; var tokenMethod = 'POST'; var tokenBody = { "userName": "XXXX@XXXX", "password": "yyyyyy" }; var tokenBody = JSON.stringify(tokenBody); var tokenResponse = https.request({ method: https.Method.POST, url: tokenURL, body: tokenBody, headers: commonHeader }); var tken = JSON.parse(tokenResponse.body); return tken; }
b
although that is not what you shared in the beginning
the debugging process is the same
log
Copy code
{
            method: <http://https.Method.POST|https.Method.POST>,
            url: tokenURL,
            body: tokenBody,
            headers: commonHeader
}
from a successful request and a failed request and compare the two
in the case where they are the same, then just hardcode the request parameters to be whatever generates a successful request and then trigger it via the rest api
to double check
general idea is to figure out whats different, if you cant, then at least start from something that should succeed
p
var tken = tokens from previously shared code; var request_header = { "Authorization": "Bearer " + tken.jwtToken, "Content-Type": "application/json" }; var json_body = updated_json; var encryptData = encryptionData(json_body, crypto, encode, 'XXXX'); var response = https.put({ url: 'XXXXX', // update base Url NIS-7513 body: JSON.stringify(encryptData), headers: request_header }); facing issue while calling PUT method of 3rd partly url
b
thats going to be more annoying to compare if your body is encoded
same idea though, compare the input to the encoding function of a successful request to a failed request
and in your case, for testing purposes, you should probably use the same jwt token if it last long enough