using TBA that is
# suitescript
k
using TBA that is
s
I have used this library in the past which does make it a lot easier to implement: https://github.com/mark-keaton/oauth-netsuite
Make sure to use SHA256, as SHA1 is now deprecated.
k
Perfect, thank you!
Just curious, why did you choose crypto.js instead of the NS native N/crypto
b
nobody likes implementing crypto
and the N/crypto module is unlike anything else that you will have to implement it yourself
if you are truly dedicated, you can probably modify the underlying library to use N/crypto, but thats a lot of work
k
got it 🙂
Hmmm... WebStorm doesn't like the oauth script in the example. It can't find the getHeaders function.
oh I have to reference it as oauth.js not just oauth
Using
https.get()
with the headers provided in the example I'm getting a null response and nothing in the restlet logs on the other end. Any ideas how to troubleshoot?
I've never seen N/https just return null before
nevermind, had a faulty if statement so it wasn't even running the get
Now I get an error 401: invalid login attempt
changed the realm suffix for the sandbox from
-sb1
to
_SB1
and now I get error 403: invalid login attempt. What could be wrong?
I've got the correct consumer key and token going into the request, and using HMAC-SHA256 which was the default from the example code, though it looks plain text to me when logging it just before sending...
I'm stumped, please help?
b
what does the code look like
k
secret.js looks identical to the example, except with my credentials
oauth.js looks the same except there's a typo in the example, in some places it's cryptojs and others it's crypto
I made it crypto everywhere
b
its a bad bet not giving me code
k
lol I'm getting there 🙂
Sorry, was trying to type while running from a bee that tried to fly up my nose >.<
true story
🤣 1
getting code now
Hmmm why can't I post a code snippet in here anymore...?
s
Click on the lightning bolt just below the typing box
Then you’ll have the option to create a text snippet
BTW, It has been a bit since I used this. Obviously, I’d first make sure you can call into the remote restlet at all, from any client (Postman, etc.) just to be sure it is working.
k
Untitled
Then in my M/R script that'll be processing the response I call it with...
Untitled
Some of the class stuff is not used yet, I've also got parsing and matching functions
but they're commented out right now
I see the problem
oh nope, it's the same in the example
gonna try the example straight instead of adapting it to my class
Same error when using the example code verbatim except the URL and credentials
I think I figured it out. The 2021.1 upgrade went through as I was coding
I bet it ate my integration
Nope. It is still there and it's hitting the access log as a failure
b
Either you are bad at copy and pasting the debugger example
or you messed up your secret.js
k
I triple checked, found one typo in the URL where I'd hit
b
after crtl+v (really bad at copy paste apparently) but still gets the same error
even tried reverting oauth.js to the code in the example and renaming a copy of crypto.js to cryptojs.js so that NetSuite could find it, still the same error...
I should be using the external URL of the restlet, right?
Any particular permissions needed for the role beyond Log In Using Access Tokens?
b
you should probably check that the tokens work in postman before moving onto your library
k
Ok I'll try that, thanks!
Yeah, same thing with Postman
b
id start with getting all 4 new tokens
k
Changed postman settings to include auth in the headers instead of the body and it got a different error! 😄
Copy code
error code: INVALID_RETURN_DATA_FORMAT
error message: Invalid data format. You should return text.
It actually hit the script log that time 😄
now to return a valid response...
isn't it just
Copy code
return "{'json':'string'}";
been a while since I've written one of these
b
depends on the suitescript version
but in general you return an object for json content type
string for plain text content type
k
ah right
changed it to object and still nothing in the response body hmm...
b
what does the postman request look like
k
GET /app/site/hosting/restlet.nl?script=700&deploy=1 HTTP/1.1
Host: [nsAccountNumber]-<http://sb1.restlets.api.netsuite.com|sb1.restlets.api.netsuite.com>
Content-Type: application/json
Authorization: OAuth realm="[nsAccountNumber]_SB1",oauth_consumer_key="[nsConsumerKey",oauth_token="[nsToken]",oauth_signature_method="HMAC-SHA256",oauth_timestamp="1619066871",oauth_nonce="1BZaCQladwJ",oauth_version="1.0",oauth_signature="BAtsr%2Bl%2FKXxT5k%2FMcs9rjhKcQKI8Q9yQ%2BaiT9LfqyGk%3D"
all the stuff in [brackets] is account specific info that I redacted for pasting here
The content length of the response is 0
but gets success code 200
I figured it out. The script record is broken and my uploads with the return value failed.
@battk @scottvonduhn Yup, that was the final problem, I've got output! Thank you for all your help!!!!
I spoke too soon. I still get the 403 invalid login error when using the example code in my script
Untitled
Headers as they appear in the script log:
Untitled
Again, things in [brackets] are redacted, not actually in the code/log
The only thing I see different really is the quotes and escaped quotes generated by the oauth.js in the example