In this guide, we will walk through the essential steps required to build a NetSuite integration using the Cobalt platform. This process involves three major steps i.e. User Authentication with NetSuite, Creating Workflows and Using workflows for users.
A Linked Account in Cobalt represents the end-users or customers who will use the integration through the platform. Each Linked Account requires a unique linked_account_id, which typically corresponds to an ID from your internal data model (e.g., a user or account ID).
After creating a Linked Account, the next step is to generate a session token. Session tokens help protect your Cobalt API key and manage end-customer tokens more securely.
To create a session token, use the following API call:
Next, you will need to generate a Hosted URL that your users will use to authenticate with Salesforce. Cobalt securely stores the credentials and handles API calls on behalf of your users.
Use the following API call to generate the Hosted URL:
The response will return a Hosted URL that your users can visit to authenticate and connect their Salesforce accounts.
Hosted Portal is a no-code solution provided by Cobalt that removes the need to build your own UI for handling integration authentication and configuration.
Consider a use-case where you want to sync all the contacts present in NetSuite to your system.
In the NetSuite integration, go to Workflows and create a new workflow by clicking on +Add Workflow button and name it as Sync Contacts.
Follow the steps given to build the workflow:
1
Add Trigger in Start Node
All workflows start with a trigger, which determines when the workflow will run and how data is passed into the workflow.
For this workflow we will use the Event Based trigger.
Click on the Start Node, select your native app option and click on + Create New Event.
Give a name to your event and keep the payload as an empty object.
2
Add NetSuite Node
Now to fetch all the contacts present in your user’s account, we need to call NetSuite API.
Click on Nodes option in the top right and drag the NetSuite Node from Native Apps section to the workflow builder. Connect this node with Start Node and select Get Contact action in the node.
3
Add Loop node
We fetched all the contacts data from NetSuite, but NetSuite API only sends the IDs of the contacts in the API response, so now we need to loop through all the IDs and get contact data.
Drag the Loop Code from the Utility Nodes section onto the workflow builder and connect it with NetSuite node.
4
Setup Loop Node
To setup how many iterations the loop node will do, click on it and select Array Iteration as action and provide the array of IDs that you received from the NetSuite node.
Inside the Loop node we will add the nodes that we want execute in loops. Add a NetSuite node inside the Loop node and select Get Contact by ID action where you provide a dynamic id based on array item by templating {{node.<Loop_node_no.>.body.array_item.id}}.
5
Table Node addition
We are looping through the NetSuite nodes, but we need to store that response in a temporary storage so that we can use it outside the loop. For this purpose, we will use the Table node.
Add a Table Node inside the Loop node and select action Add Table Record to create new rows of data in it.
Before you can add data to a Table, you need to create a Table in the workflow. You can do this step before executing the Loop node and selecting the action Create Table, which you will then use inside Loop.
6
Fetch all records
Once the iterations are finished, you need to fetch all the records that were added to the Table.
Add a Table node to the Loop node and select Get Table Records action and provide the ID of the table where you added records.
7
Mapping Contact fields
Click on + Map Fields under Input Parameters, add key name as contacts and in value we will provide the response received through Table node which will be restructured.
In Value, select Nodes tab under Insert Variable and click on + of the Table Node where you fetched all records.
You can now do mapping using JavaScript code. Try the sample code provided below:
yourFunction
functionyourFunction(params){return params.contacts.records.filter((record)=>{const{ data }= record;// Remove record if email is empty and either description or phone is emptyreturn!((!data.email|| data.email.trim()==="")&&(!data.description|| data.description.trim()===""||!data.phone|| data.phone.trim()===""));}).map((record)=>{const{ data }= record;// Extract company name from email if it's missingif(!data.company_name|| data.company_name.trim()===""){const emailDomain = data.email.split("@")[1];if(emailDomain){let company = emailDomain.split(".")[0];// Extract the part before the first dot data.company_name= company.charAt(0).toUpperCase()+ company.slice(1);// Capitalize first letter}}// Set default value for description if it's missing or emptyif(!data.description|| data.description.trim()===""){ data.description="No description available";}// Set default value for phone if it's missing or emptyif(!data.phone|| data.phone.trim()===""){ data.phone="Not available";}return data;});}
8
API Proxy in Workflow
You have successfully fetched all contacts and structured the payload. Now to receive it in your server, you need to configure an API Proxy.
In Cobalt Dashboard, navigate to Developer > API Proxies and click on New Action. Configure an API endpoint, where you want to receive the response.
If you want to test, go to webhook.site and copy Your unique URL and configure this as a POST Request and Save.
Consider a use-case where you want to create a contact present in your system to NetSuite.
This workflow will be fired when you send an Event with the payload of the contact to be added.
In the NetSuite integration, go to Workflows and create a new workflow by clicking on +Add Workflow button and name it as Create New Contact.
Follow the steps given to build the workflow:
1
Add Trigger in Start Node
All workflows start with a trigger, which determines when the workflow will run and how data is passed into the workflow.
For this workflow we will use the Event Based trigger.
Click on the Start Node, select your native app option and click on + Create New Event.
Give a name to your event and provide all the data related to the contact in the payload.
2
Add NetSuite Node
Now to create a new contact in NetSuite, we need to call NetSuite API.
Click on Nodes option in the top right and drag the NetSuite Node from Native Apps section to the workflow builder. Connect this node with Start Node.
3
Add Action in node
Click on NetSuite Node and add the Create Contact action.
To provide the data in all the fields from your Event payload, just click on a field and from the Event tab under Insert Variable, select the fields from the body that you sent as payload.
Ensure that all the mandatory fields in the action are filled, else the NetSuite API will give error.
Hurray!!
You have successfully created a NetSuite workflow to create a new contact.
You have successfully created the workflows for your use case.
Next step is to enable and execute those workflows for your Linked Accounts.
You can create config for the Linked Account through the Cobalt Connect SDKs or using the APIs.
You can use the .config() method or the Create Config API which returns the specified config or creates one if it doesn’t exist for the Linked Account.
Make a request with the Application Slug and linked_account_id as mandatory fields for it. You can request in the following way:
It will return information about config of the application for the Linked Account and provides you with all the published workflows and settings input for the user required to execute the workflow.
Now you need to enable the workflow for your Linked account. You can either ask the user to enable them or you can do so for them by using the Update Config API or .updateconfig() method.
In response, you get the updated config information for the application.
3
Third Step
Once the required workflows are enabled, you need to fire event to start execution. You can use the Trigger Event for app API with the following request: