How to use postman for Netsuite SOAP API
It a bit complex to setup & get everything right to setup Netsuite SOAP API with Postman. This postman based flow would be helpful to debug if you are building SOAP based data integration with Netsuite.
Pre-requisites
Netsuite login credentials :
- ACCOUNT
- CONSUMER_KEY
- CONSUMER_SECRET
- TOKEN_ID
- TOKEN_SECRET
Postman environment
Create a Postman environment. This would help to hold variables. Add the above information as variables :
Create a POST request
Create a POST request. No difference so far between normal REST postman request & SOAP request till now. Upcoming steps will make it a SOAP request.
Add following javascript as Pre-request
scripts :
let account = pm.environment.get("ACCOUNT");
let consumerKey = pm.environment.get("CONSUMER_KEY");
let consumerSecret = pm.environment.get("CONSUMER_SECRET");
let tokenId = pm.environment.get("TOKEN_ID");
let tokenSecret = pm.environment.get("TOKEN_SECRET");
var CryptoJS = require("crypto-js");
let timestamp = new Date().getTime().toString().substring(0, 10);
let nonce = CryptoJS.lib.WordArray.random(10).toString();
let baseString = `${account}&${consumerKey}&${tokenId}&${nonce}&${timestamp}`;
let key = `${consumerSecret}&${tokenSecret}`;
let signature = CryptoJS.HmacSHA256(baseString, key).toString(CryptoJS.enc.Base64);
pm.environment.set("signature", signature);
pm.environment.set("nonce", nonce);
pm.environment.set("timestamp", timestamp);
- The above script does
HmacSHA256
encryption. - Credits for the above script goes to michoel chaikin’s gist. Fixed couple of issues in that script and added SHA256 encryption.
POST request URL should be of the following format :
https://<account_id>.suitetalk.api.netsuite.com/services/NetSuitePort_2024_1
POST request Headers
- In the above screenshot, we are using the SOAP request for invoking search. Based on SOAP action, we need to update the values here.
POST request body
<soap:Envelope xmlns:platformFaults="urn:faults_2024_1.platform.webservices.netsuite.com"
xmlns:platformMsgs="urn:messages_2024_1.platform.webservices.netsuite.com"
xmlns:platformCore="urn:core_2024_1.platform.webservices.netsuite.com"
xmlns:tranSales="urn:sales_2024_1.transactions.webservices.netsuite.com"
xmlns:tranPurch="urn:purchases_2024_1.transactions.webservices.netsuite.com"
xmlns:tranGeneral="urn:general_2024_1.transactions.webservices.netsuite.com"
xmlns:platformCommon="urn:common_2024_1.platform.webservices.netsuite.com"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<platformMsgs:searchPreferences>
<pageIndex>1</pageIndex>
<pageSize>5</pageSize>
<bodyFieldsOnly>false</bodyFieldsOnly>
<platformMsgs:returnSearchColumns>false</platformMsgs:returnSearchColumns>
</platformMsgs:searchPreferences>
<tokenPassport>
<account>{{ACCOUNT}}</account>
<consumerKey>{{CONSUMER_KEY}}</consumerKey>
<token>{{TOKEN_ID}}</token>
<nonce>{{nonce}}</nonce>
<timestamp>{{timestamp}}</timestamp>
<signature algorithm="HMAC-SHA256">{{signature}}</signature>
</tokenPassport>
</soap:Header>
<soap:Body>
<platformMsgs:search>
<platformMsgs:searchRecord xsi:type="tranSales:TransactionSearchAdvanced" savedSearchId="12">
<tranSales:criteria>
<tranSales:basic>
<platformCommon:tranId operator="contains">
<platformCore:searchValue>123</platformCore:searchValue>
</platformCommon:tranId>
</tranSales:basic>
</tranSales:criteria>
</platformMsgs:searchRecord>
</platformMsgs:search>
</soap:Body>
</soap:Envelope>
- pageSize in the above sample, acts as a limit for the search results
tokenPassport
will be updated based on the pre-request output. Other parts of the soap request is based on our needs.
- We need to change the Body type to
raw
and content type toXML
We should now be able to get SOAP response.
Thoughts about SOAP UI
For this usecase, I tried to use SOAP UI. However, for me, I felt the usability is not great in SOAP UI. I couldn’t neither get it working nor get useful community information to resolve issues.