https://netsuiteprofessionals.com logo
c

CaroLab

04/11/2022, 2:03 PM
Hello there! I'm trying to send a post request with suiteql in order to get all items, using javascript fetch. It works fine when I use the url "https://my_account.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql", but I get a "401 Unauthorized" error when I add limit and offset to the url (like this : "https://my_account.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=1000&offset=1000") and I didn't change anything in the authentication method. Any idea ?
1
j

jen

04/11/2022, 8:41 PM
Can you share your SQL? Be aware that
LIMIT
and
OFFSET
are not supported in SuiteQL AFAIK
m

michoel

04/11/2022, 9:42 PM
How are you generating the oauth signature? I'm guessing the URL parameters aren't being included in the base string
c

CaroLab

04/12/2022, 8:32 AM
@jen Here is my SQL : "SELECT id FROM item WHERE itemtype = 'Assembly' ORDER BY id"
@michoel Should I include the limit and offset parameters in the url used to generate the signature or not ? When I generate the signature using the base URL "https://my_account.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql", it works but I am not able to get results with limit and offset parameters. I don't know how to make it work
This my code to generate the signature :
Copy code
const collectedString = `oauth_consumer_key=${consumerKey}&oauth_nonce=${nonce}&oauth_signature_method=${signatureMethod}&oauth_timestamp=${time}&oauth_token=${token}&oauth_version=${version}`;

const encodedString = encodeURIComponent(collectedString);
const encodedUrl = encodeURIComponent(url);

const base = `POST&${encodedUrl}&${encodedString}`;
const key  = `${consumerSecret}&${tokenSecret}`;

const signature = createHmac('sha256', key).update(base).digest('base64');
m

michoel

04/12/2022, 9:33 AM
Yes the query string parameters have to be included in the base string that is signed. https://datatracker.ietf.org/doc/html/rfc5849#section-3.4.1.3.1
👌 1
c

CaroLab

04/12/2022, 12:16 PM
@michoel Thank you very much !! I finally made it work 🥳
3 Views