Aditya Viki
11/08/2024, 9:15 AMCeligo AI
11/08/2024, 9:15 AMAI generated answer (using internal Slack threads):To set up SuiteQL API on Axios using OAuth 1.0, you can follow the steps below: 1. First, you need to install the necessary libraries. You can use
oauth-1.0a
for OAuth 1.0 authentication and node-fetch
for making HTTP requests. You can install these libraries using npm:
npm install oauth-1.0a node-fetch
2. Next, you need to create an OAuth object with your consumer key and secret:
javascript
const OAuth = require('oauth-1.0a');
const crypto = require('crypto');
const oauth = OAuth({
consumer: {
key: '<CONSUMER_KEY>',
secret: '<CONSUMER_SECRET>'
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return crypto
.createHmac('sha1', key)
.update(base_string)
.digest('base64');
}
});
3. Then, you need to create a request data object with your SuiteQL query:
javascript
const request_data = {
url: 'https://<ACCOUNT_ID>.<http://suitetalk.api.netsuite.com/services/rest/query/v1/suiteql|suitetalk.api.netsuite.com/services/rest/query/v1/suiteql>',
method: 'POST',
data: { q: 'SELECT * FROM Budget' }
};
4. You also need to create a token object with your token key and secret:
javascript
const token = {
key: '<TOKEN>',
secret: '<TOKEN_SECRET>'
};
5. Now, you can authorize your request data with your token and create an Authorization header:
javascript
const auth = oauth.toHeader(oauth.authorize(request_data, token)).Authorization;
6. Finally, you can make a POST request to the SuiteQL API using `node-fetch`:
javascript
const fetch = require('node-fetch');
fetch(request_data.url, {
method: 'POST',
headers: {
Authorization: auth,
'Content-Type': 'application/json',
Cookie: 'NS_ROUTING_VERSION=LAGGING',
prefer: 'transient'
},
body: JSON.stringify(request_data.data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.error('err: ', err));
Please replace <CONSUMER_KEY>
, <CONSUMER_SECRET>
, <ACCOUNT_ID>
, <TOKEN>
, and <TOKEN_SECRET>
with your actual values.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
11/08/2024, 9:16 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827545583
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.810825109
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.810617566
Celigo AI
11/08/2024, 9:16 AM