---
schema_version: "1"
id: 73ad3a0da5c7d80ce8fdb2b9316052957fb0ab21003f3f6e43ff6f9b9bfb1599
title: Call NetSuite RESTlets Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/netsuite-restlet-connector/latest/netsuite-restlet-call-restlets-example.md
canonical_url: https://docs.mulesoft.com/netsuite-restlet-connector/latest/netsuite-restlet-call-restlets-example
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f3c30da799fed6167fde3c6adff7c36d7fb85adb48b498d65315e741d2686678
description: MuleSoft Documentation Site
release: "1.0"
latest: true
---
---
product: NetSuite Restlet Connector
version: 1.0
is-latest-version: true
---

# Call NetSuite RESTlets Example

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This example shows how to:

- Create a script that calls NetSuite RESTlets that are deployed in NetSuite instances to create,
  retrieve, and delete a customer record

- Deploy the RESTlet script

- Configure the application’s properties to connect to NetSuite and deploy the app

## Create and Deploy a Script as a RESTlet

Create and then deploy a script that creates, retrieves, and deletes a customer record:

1.  Create a sample JavaScript script:

    ```javascript
    // Get a standard NetSuite record
    function getRecord(datain) {
      return nlapiLoadRecord(datain.recordtype, datain.id);
      // for example, recordtype="customer", id="769"
    }

    // Create a standard NetSuite record

    function createRecord(datain) {
      var err = new Object();

      // Validate if mandatory record type is set in the request
      if (!datain.recordtype) {
        err.status = "failed";
        err.message = "missing recordtype";
        return err;
      }

      var record = nlapiCreateRecord(datain.recordtype);

      for (var fieldname in datain) {
        if (datain.hasOwnProperty(fieldname)) {
          if (fieldname != "recordtype" && fieldname != "id") {
            var value = datain[fieldname];
            if (value && typeof value != "object")
            // ignore other type of parameters
            {
              record.setFieldValue(fieldname, value);
            }
          }
        }
      }
      var recordId = nlapiSubmitRecord(record);
      nlapiLogExecution("DEBUG", "id=" + recordId);
      var nlobj = nlapiLoadRecord(datain.recordtype, recordId);
      return nlobj;
    }

    // Delete a standard NetSuite record
    function deleteRecord(datain) {
      nlapiDeleteRecord(datain.recordtype, datain.id);
      // for example: recordtype="customer", id="769"
    }
    ```

2.  Enable SuiteScript and NetSuite Web Services in your account:

    1.  Log in to NetSuite.

    2.  Click **Set Up > Company > Enable Features > SuiteCloud**:

        ![Enable SuiteScript page](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-enable-suitescript.png)

3.  Upload the file you [previously created](#deploy-a-script-as-restlet):

    1.  Go to **Customization > Scripting > Scripts > New**.

    2.  Select the script file, click **Create Script Record**, and select **RESTlet**:

        ![Select Script Type page](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-script-type.png)

4.  Complete the form using the content of the script you uploaded, and deploy the script:

    ![Setup Script page](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-setup-script.png)

5.  Select your audience to view the following page:

    ![Script Deployment page](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-script-deployment.png)

6.  Write down the script and deploy numbers that appear in the external URL, because you need them
    to call the RESTlet later.

## Create a Mule Project

In Studio, create a new Mule project and configure the credentials, deployed script, and deploy IDs
to connect to NetSuite:

1.  In Studio, select **File > New > Mule Project**.

2.  Enter a name for your Mule project and click **Finish**.

3.  In **Package Explorer**, open the `src/main/resources/mule-app.properties` file that is located
    in the Studio project you created.

4.  Configure the following values:

    ```javascript
    netsuite.email=
    netsuite.password=
    netsuite.account=
    netsuite.roleId=
    netsuite.applicationId=
    netsuite.subsidiary=
    netsuite.script=
    netsuite.deploy=
    ```

    The `netsuite.script` and `netsuite.deploy` values are the values you wrote down in the last
    step of [Create and Deploy a Script as a RESTlet](#deploy-a-script-as-restlet).

## Add the Connector to Your Mule Project

Add NetSuite Connector to your Mule project to automatically populate the XML code with the
connector’s namespace and schema location and add the required dependencies to the project’s
`pom.xml` file:

1.  In the **Mule Palette** view, click **(X) Search in Exchange**.

2.  In **Add Modules to Project**, type `netsuite` in the search field.

3.  Click the connector name in **Available modules**.

4.  Click **Add**.

5.  Click **Finish**.

## Create the App Flow

1.  In the Studio canvas, click **Configuration XML**.

2.  Delete all the contents after the line `<?xml version="1.0" encoding="UTF-8"?>`.

3.  Copy and paste the following XML after the line `<?xml version="1.0" encoding="UTF-8"?>`:

    ```xml
    <mule xmlns:netsuite-restlet="http://www.mulesoft.org/schema/mule/netsuite-restlet"
          xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
          xmlns:http="http://www.mulesoft.org/schema/mule/http"
          xmlns="http://www.mulesoft.org/schema/mule/core"
          xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
    http://www.mulesoft.org/schema/mule/netsuite-restlet http://www.mulesoft.org/schema/mule/netsuite-restlet/current/mule-netsuite-restlet.xsd">
    	<configuration-properties file="mule-app.properties" doc:name="Configuration properties"/>
    	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
    		<http:listener-connection host="0.0.0.0" port="8081" />
    	</http:listener-config>
    	<netsuite-restlet:rest-config name="NetSuite_Rest_config" doc:name="NetSuite Rest config" >
    		<netsuite-restlet:restlet-token-connection
    				consumerKey="${netsuite.consumerKey}"
    				consumerSecret="${netsuite.consumerSecret}"
    				tokenId="${netsuite.tokenId}"
    				tokenSecret="${netsuite.tokenSecret}"
    				account="${netsuite.account}"
    				readTimeout="${netsuite.readTimeout}"
    				connectionTimeout="${netsuite.connectTimeout}"/>
    	</netsuite-restlet:rest-config>
    	<flow name="html-form-flow">
            <http:listener config-ref="HTTP_Listener_config" path="/" doc:name="/"/>
            <parse-template location="form.html" doc:name="Parse Template"/>
        </flow>
        <flow name="restletGet">
            <http:listener config-ref="HTTP_Listener_config" path="/get" doc:name="/get"/>
            <ee:transform doc:name="Transform GET Input" >
    			<ee:message >
    				<ee:set-payload ><![CDATA[%dw 2.0
    output application/java
    ---
    {
        "id": attributes.queryParams.id,
        "recordtype": attributes.queryParams.recordtype
    }]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
            <netsuite-restlet:call-restlet-get config-ref="NetSuite_Rest_config" script="${netsuite.script}" deploy="${netsuite.deploy}" doc:name="Call RESTlet (GET)" />
            <ee:transform doc:name="to JSON" >
    			<ee:message >
    				<ee:set-payload ><![CDATA[%dw 2.0
    output application/json
    ---
    payload]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
            <logger level="INFO" doc:name="Logger"/>
        </flow>
        <flow name="restletPost">
            <http:listener config-ref="HTTP_Listener_config" path="/post" doc:name="/post"/>
            <ee:transform doc:name="Transform POST Input" >
    			<ee:message >
    				<ee:set-payload ><![CDATA[%dw 2.0
    output application/java
    ---
    payload]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
            <netsuite-restlet:call-restlet-post config-ref="NetSuite_Rest_config" deploy="${netsuite.deploy}" script="${netsuite.script}" doc:name="NetSuite RESTlet (POST)"/>
            <ee:transform doc:name="to JSON" >
    			<ee:message >
    				<ee:set-payload ><![CDATA[%dw 2.0
    output application/json
    ---
    payload]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
            <logger level="INFO" doc:name="Logger"/>
        </flow>
        <flow name="restletDelete">
            <http:listener config-ref="HTTP_Listener_config" path="/delete" doc:name="/delete"/>
            <ee:transform doc:name="Transform DELETE Input" >
    			<ee:message >
    				<ee:set-payload ><![CDATA[%dw 2.0
    output application/java
    ---
    {
        "id": attributes.queryParams.id,
        "recordtype": attributes.queryParams.'recordtype'
    }]]></ee:set-payload>
    			</ee:message>
    		</ee:transform>
            <netsuite-restlet:call-restlet-delete config-ref="NetSuite_Rest_config" deploy="${netsuite.deploy}" script="${netsuite.script}" doc:name="NetSuite RESTlet (DELETE)"/>
            <set-payload value="Record deleted successfully" doc:name="Set Payload"/>
            <logger  level="INFO" doc:name="Logger"/>
        </flow>
    	</mule>
    ```

4.  Save the project.

### About the Flows

1.  The `html-form` flow renders the HTML form with a `parseTemplate` component:

    ![HMTL Form Studio flow](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-html-form-flow.png)

2.  The `restletGet` flow calls the GET function of a RESTlet:

    ![Restlet Get Studio flow](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-restlet-get.png)

3.  The `restletPost` flow calls the POST function of a RESTlet:

    ![Restlet Post Studio flow](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-restlet-post.png)

4.  The `restletDelete` flow calls the DELETE function of a RESTlet:

    ![Restlet Delete Studio flow](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-restlet-delete.png)

## Run the App

Run, deploy, and verify the app:

1.  Click **Global Elements** at the base of the project’s canvas.

2.  In **Global Configuration Elements**, select **NetSuite Rest config** and click **Edit**.

3.  Click **Test Connection** to ensure there is connectivity with the sandbox.

    A success message appears:

    ![Test connection successful message](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-demo-connection-test.png)

4.  Click the project name in **Package Explorer** and click **Run > Run As > Mule Application**.  
    In the console, look for the message `Mule is up and kicking` to verify that the application
    started successfully.

5.  Open a browser and access the URL `http://localhost:8081`.  
    You can see that the application deployed:

    ![Demo page](/mulesoft/current/en-us/netsuite-restlet-connector/latest/_images/netsuite-demo-main-page.png)

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [NetSuite Connector Overview](https://docs.mulesoft.com/netsuite-restlet-connector/latest/)

- [NetSuite Connector Reference](https://docs.mulesoft.com/netsuite-restlet-connector/latest/netsuite-restlet-connector-reference)

- [Salesforce Help](https://help.salesforce.com)
