NetSuite REST API Integration With Mulesoft Using OAuth2
October 30, 2024
NetSuite REST API Integration With Mulesoft Using OAuth2
The SuiteTalk platform integrates NetSuite with a variety of on-premise applications and third-party cloud environments by leveraging CSV, SOAP and REST web services. This can be used to build website-to-NetSuite integrations or custom mobile applications. NetSuite's REST web services provide a REST-based interface for interacting with NetSuite and extend the capabilities of SuiteTalk.NetSuite's REST web service is an easy-to-navigate API, giving users access to company-specific records metadata. It allows for easy handling of custom records and fields, and no requirement for users to write, deploy and run custom scripts as in the case of RESTlets. This API is still in the beta stage in Netsuite, but the Integration team at Tvarana has successfully integrated it with the Mulesoft platform using OAuth2 to fetch data from NetSuite.Oauth 2.0 authentication of Netsuite in Mulesoft Anypoint Studio has been configured as follows:1.Add a listener to the flow and give the respective listener configuration and path.2. Drag and drop a HTTP Request operation from Mule palette.
3. Request Configuration for Netsuite Oauth Authentication:
Add a Request configuration, change the name of the configuration as required, and select the protocol from the given drop-down list (HTTPS)
Enter the host as <netsuite-account-id>.suitetalk.api.netsuite.com
The base path would be /services/rest/record/v1
In the Authentication Type as “Authorization Code grant type” (if this authentication type is not available in the drop down then you haven’t added the Oauth module).
The Local Callback configuration, shown in the figure above, uses a different Listener configuration for the callback. The Listener configuration would look like
Click Ok to return to the Request Configuration. Add /callback as the Local Callback configuration path. The external callback URL is the redirect URL entered in the users's NetSuite account. State value can be any random string like (ykv2XLx1BpT5Q0F3MRPHb94l)
Local Authorization URL is the main URL through which incoming requests are sent and outgoing requests are received. It is important to note that the Local Authorization URL and Local Callback URL must have the same port and cannot be left empty. The Local Authorization URL would be https://localhost:8082/web
Once the flow has been deployed, apply the listener configured in the steps above. User will see the error message- No Access Token Found
In the Mulesoft console, the error message looks like the screenshot below
This error has occurred because an access token was not generated. In order to generate the access token, the Local Authorization URL needs to be triggered. Once this is done, the user will be redirected to Netsuite Login page
After logging into their NetSuite account, the user is redirected to the permission page, seen in the screenshot below
Click on continue to be redirected to a page with the message- Successfully retrieved access token
This completes the generation of access token. Now trigger the listener to view the result, in this case, the list of customers (the result is in the form of URLs)