So this is a weird one. I’m trying to create a si...
# suitescript
j
So this is a weird one. I’m trying to create a single Suitelet (on Production) that calls RESTlets on our Sandboxes, to retrieve some data from all the SBs and PROD together (it will be a list of all users on each account and what roles they have). When my Suitelet tries to call my RESTlet on SB1, I get this
Copy code
{
  "error": {
    "code": "INVALID_DATA_CENTER",
    "message": "Incorrect data center requested! The data center you are requesting is not the data center where your account is hosted. To obtain the correct URL for your request, please use the following endpoint: <https://rest.netsuite.com/rest/datacenterurls?account=><our_account_id>. Then, send your original request to the correct data center."
  }
}
I’m using the external URL of the SB1 RESTlet when making my call from the PROD Suitelet, and I’m passing the appropriate consumer/token id/secrets via OAuth.
b
do the tokens work in postman
j
I don’t have postman. I don’t think it’s even getting as far as checking the token though
b
then dont send any authorization related headers
if you get the same error, its not related to tokens or realm
j
that’s what I tried already. If I send no tokens, I get the same error INVALID_DATA_CENTER
b
what does the script look like
j
My Suitelet is basically this:
Copy code
// Generate the OAuth Headers.
var headers = oauth.getHeaders({
url: env.url,
method: 'GET',
consumerKey: env.consumer_id,
consumerSecret: env.consumer_secret, 
tokenKey: env.token_id,
tokenSecret: env.token_id
});

headers['Content-Type'] = 'application/json';

// Get the Response from the RESTlet. 
var response = https.get({
url: env.url,
headers: headers
});
where env.url is like
https://<myaccountid>-<http://sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1925&deploy=1|sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1925&deploy=1>
if I make env.url = ’https://www.google.com' I don’t get the above error
e
download postman and make sure your restlet call works there. what about the REALM for example?
Signature Method, too
b
share enough of the script to reproduce the problem, you dont show how you setup oauth
or more favorable, show a version of the script without oauth if its not needed to reproduce the problem
j
I think it’s a realm thing @ec
Have either of you successfully accessed a Sandbox using OAuth/Tokens?
b
its the same as production, though you can no longer make the mistake of assuming that the domain of the url is the same as the account id
invalid data center suggests that your request contains the wrong account id somewhere, though you have not shared enough code to determine where that account id is coming from
j
dang I’m getting INVALID_LOGIN_ATTEMPT now, both in my code and postman. I regenerated my tokens but no joy.
am setting my
realm
to include _SB1
I’m not sure what else to share in the code other than my tokens
b
reasonable place to start is what was suggested in the beginning
get postman to work
you havent shared the code behind the oauth variable, so we cant confirm if that code works or not
in the absence of that, the suggestions were to use postman to see if the tokens/realm work
and worry about the code later
so you would need to share how you configured postman to make a request to the restlet
alternatively you can take a look at how netsuite describes how to Work with REST Web Services Using Postman
the settings used to do the authorization are the same you would need to use for restlets
j
you havent shared the code behind the oauth variable, so we cant confirm if that code works or not
I’m using a library that we use for other requests (to prod) which works find there
b
another place to look would be TBA and the Login Audit Trail
the code you shared doesnt have enough information to make a request to production and sandbox unless there is specific logic for sandbox and production
j
I’m not sure what you mean
b
Copy code
var headers = oauth.getHeaders({
url: env.url,
method: 'GET',
consumerKey: env.consumer_id,
consumerSecret: env.consumer_secret, 
tokenKey: env.token_id,
tokenSecret: env.token_id
});
j
I’m trying to request a url that lives on SB1, from a suitelet that runs on prod
b
there is no place to get the account id from the parameters
unless its from the url
which is not going to be correct for sandbox
I have my actual account id where that says <myaccountid>
e.g. 123456-sb1 etc
b
thats not the account id of your sandbox
j
well I’ve tried specifying the REALM as e.g. 123456_SB1 and it doesn’t make any difference
I’ve not needed to provide “account id” in https.get calls previously so I’m not sure where I should be putting that?
besides
realm
b
thats where you would need to provide it
and you havent shared the logic behind it
from what you have shared so far, it doesnt look correct
thats a problem for later
you want to make sure you have your tokens and realm correct
then mess around with your code
you will have a much harder time writing correct code if you dont have the realm and tokens correct
j
yes well I put the correct realm and tokens into postman and got INVALID_LOGIN_ATTEMPT still, so I’m not sure what else to try.
it simply seems to not work when I try with a sandbox.
I’ve successfully done this sort of thing on prod before
so I’m not a COMPLETE n00b
b
start with postman
get the authorization working
if you dont know how
either share what you filled in on the authorization tab
or learn how netsuite does it in its collection
j
message has been deleted
message has been deleted
ugh. I can’t even get postman to work on prod, for requests I’ve got running properly in NS. So I clearly don’t know how Postman works.
b
you are adding the authorization data to the request body/url
its supposed to go in the headers
you are also missing one of the authorization settings
there are 16, you shared 15
j
Why does postman have an authorization tab with 4 boxes for tokens if that’s not where I put the tokens
b
it is where you put them
j
what did you mean by this then “battk [3:30 PM] you are adding the authorization data to the request body/url battk [3:30 PM] its supposed to go in the headers”
b
message has been deleted
j
ah
ooh
it worked
ok so my tokens are fine, that’s a good start
b
and now we are at the point where you know its the code
j
yeah
b
you will have to share your code if you want help on that
though usually I recommend https://www.npmjs.com/package/oauth-1.0a
j
no idea what I just did different but…it worked in code now
YUSS
Thank you
good to know how to test in PM to rule out token issues
147 Views