01
NetSuite StorageKnow more

In MuleSoft, we can use the Web Service Consumer to connect to NetSuite, allowing us to access and interact with NetSuite data efficiently. It supports operations such as sending SOAP requests, handling authentication, and processing paginated results.However, direct SOAP integration may pose challenges with token-based authentication and XML transformation, particularly when dealing with complex workflows. The following steps outline how to set up and execute a connection to NetSuite using MuleSoft.
Web Service Consumer ConnectorThe Web Service Consumer connector in Mule 4 is a powerful tool that makes it simple to integrate with SOAP-based web services. The Web Service Consumer connector is ideal for consuming WSDL-based SOAP services, especially when no pre-built connector exists. It also supports advanced use cases like handling large datasets with pagination.The Web Service Consumer supports SOAP multipart messages, headers, and attachments with embedded DataWeave transformations for enhanced flexibility.Retrieving a Saved Search from Netsuite using Web service consumerStep 1: Setting Up the Connector Configuration
To get started, you’ll need to:
or login into your Netsuite account, Navigate Setup> Company > Company Information and click the Company URLs subtab to view the account-specific domains. Use the Suite Talk URL. Once the Connection is done we can select the operations that are available in the WSDL file.When calling a SOAP operation, you'll encounter three main components:
To connect with NetSuite using SOAP, you must generate a token-based authentication header dynamically for each request. Use the following steps to generate the tokenPassport header dynamically in a DataWeave script.
Dataweave Code for Header:import dw::Cryptoimport * from dw::core::Binariesns platformMsgs urn:messages_2024_1.platform.webservices.netsuite.comns core urn:core_2024_1.platform.webservices.netsuite.comns ns0 urn:messages_2024_1.platform.webservices.netsuite.comns ns01 urn:core_2024_1.platform.webservices.netsuite.comvar accountId = p('AccountId')var consumerKey = p('ConsumerKey')var tokenId = p('TokenId')var consumerSecret = p('consumerSecretret')var tokenSecret = p('tokenSecretret')var randomNum = ((uuid() splitBy "-") joinBy "")[1 to 20]var timeStamp = (now() >> "GMT") as Numbervar baseString = [accountId,consumerKey,tokenId,randomNum,timeStamp] joinBy '&'var keyString = [consumerSecret,tokenSecret] joinBy '&'var afterHash = toBase64((Crypto::HMACBinary(keyString, baseString, "HmacSHA256")))---{ headers: { platformMsgs#searchPreferences:{ pageSize: 100, bodyFieldsOnly:false }, platformMsgs#tokenPassport: { core#account: accountId, core#consumerKey: consumerKey, core#token: tokenId, core#nonce: randomNum, core#timestamp: timeStamp, core#signature @("algorithm": "HMAC-SHA256"): afterHash } }}In the headers, add the search preferences with a page size of 10. This will paginate the results, retrieving only the first 10 items of the search.
Configure the Web Service Consumer to point to the NetSuite SOAP API endpoint, In the SOAP body Transform the request payload into a SOAP-compatible XML using Dataweave. Use the SavedSearchId to construct a SOAP request with the appropriate NetSuite namespace that retrieves the saved search from NetSuite.
This request will return the first 10 results, along with the “searchId”, “pageSize”and the current index in the field “PageIndex”. These values can then be used to retrieve subsequent pages by invoking another Web Service Consumer operation with the SearchMoreWithId operation.
Use the searchMoreWithId SOAP operation to handle paginated results. This is implemented in the MuleSoft flow
“(1 to payload.body.searchResponse.searchResult.totalPages as Number)” For example, if the “totalPages” are 10 then the payload will be [1,2,3,4,5,6,7,8,9,10]
Parallel For Each: Iterates over the array of Indexes in parallel, to process multiple records concurrently. This can speed up processing if there are many records to handle.