Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

To Configure the NetSuite Connecter in Studio 7

You can use this connector in Anypoint Studio by adding it as a dependency in your Mule application.

Install Connector in Studio

  1. Open your Mule project in Anypoint Studio.

  2. Add the connector as a dependency in the pom.xml file:

    <dependency>
      <groupId>org.mule.connectors</groupId>
      <artifactId>mule-netsuite-connector</artifactId>
      <version>8.0.0</version>
      <classifier>mule-plugin</classifier>
    </dependency>

Configure in Studio

  1. Drag and drop the connector to the Studio Canvas.

  2. Select an authentication mechanism listed on the Global connector configuration. It can be one of the followings:

    Configuration Description

    Login Authentication

    Makes use of the SuiteTalk’s login API call on the first request sent by the connector to establish a session with NetSuite.

    Request Based Authentication

    Using this strategy, you can send user credentials in the SOAP header of each request instead of authenticating to NetSuite by invoking login.

    Single Sign-On Authentication

    This is a token based authentication system that avoids the use of environment username and password. Here you supply a privateKey together with other information. The connector is then responsible for generating an authentication token and establishing a session with NetSuite via the ssoLogin API call on the first request.

    Token Authentication

    Similar to Single Sign-On Login Authentication, this is a token based authentication system. However, instead of using a privateKey generated via openssl, this uses a consumer and token key/secret pairs which are established within the NetSuite environment.

  3. Configure these fields according your selection:

    1. Login Authentication

      login authentication

      Parameter Description

      Name

      Enter a name for the configuration with which to reference it later.

      Email

      Enter the login email of the NetSuite UI.

      Password

      Enter the corresponding password to log into NetSuite UI.

      Account

      Enter the account ID of the SuiteTalk NetSuite web services. This is usually found within NetSuite sandbox UI under Setup > Integration > Web Service Preferences.

      Role Id

      Enter the role ID for the user in SuiteTalk, which determines the Processor privileges.

      Application Id

      Enter the application ID corresponding to the Integration record to be used.

    2. Request Based Authentication

      request based authentication

      Parameter Description

      Name

      Enter a name for the configuration with which to reference it later.

      Email

      Enter the login email of the NetSuite UI.

      Password

      Enter the corresponding password to log into NetSuite UI.

      Account

      Enter the account ID of the SuiteTalk NetSuite web services. This is usually found within NetSuite sandbox UI under Setup > Integration > Web Service Preferences.

      Role Id

      Enter the role ID for the user in SuiteTalk, which determines the Processor privileges.

      Application Id

      Enter the application ID corresponding to the Integration record to be used.

    3. SSO Authentication

      request based authentication

      Parameter Description

      Name

      Enter a name for the configuration so it can be referenced later.

      SSO Library

      Add your SSO dependency as a Maven dependency format once you click Add Dependency.

      Partner Id

      Enter the partner ID used in the mapping process.

      Partner Account

      Enter the account ID of the SuiteTalk NetSuite web services.

      Company ID

      Enter the company ID used in the mapping process for the connector to generate a token.

      User ID

      Enter the user ID used in the mapping process for the connector to generate a token.

      Key File

      Enter the privateKey file name to pick up from the project. This file should be the .der file generated as per NetSuite’s specifications. This is used to encrypt the company ID and user ID into a token for ssoLogin.

      Application Id

      Enter the application ID corresponding to the Integration record to be used.

    4. Token Authentication

      request based authentication

      Parameter Description

      Consumer Key

      Enter the consumer key value for the token based authentication enabled integration record being used.

      Consumer Secret

      Enter the consumer secret value for the token based authentication enabled integration record being used.

      Token ID

      Enter the token id representing the unique combination of a user and integration generated within the NetSuite environment.

      Token Secret

      Enter the respective token secret for the user/integration pair.

      Account

      Enter the account ID of the SuiteTalk NetSuite web services. This is usually found within NetSuite sandbox UI under Set Up > Integration > Web Service Preferences.

      Signature algorithm

      Type of HMAC signature algorithm

Use Case: Studio

NetSuite RESTlet Use Case

This use case shows how to call RESTlets that are deployed in NetSuite instances.

By following these instructions, you can:

  • Create a customer record.

  • Retrieve a customer record.

  • Delete a record.

Prerequisites

  • Java 8

  • Anypoint Studio 7.0.x

  • Mule Runtime 4.0.x EE

  • DataWeave 2.0

  • Access to a NetSuite instance with credentials in the mule-app.properties file

Deploy a Script as a RESTlet

  1. Create a sample JavaScript script:

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    
    // 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 web services in your account. Log into NetSuite and click Set Up > Company > Enable Features > SuiteCloud.

    Enable SuiteScript

  3. Create a new script and upload the file created before. Go to Customization > Scripting > Scripts > New.

  4. Pick the script file, click Create Script Record, and select RESTlet.

    Select Script Type

  5. Fill out the form using the content of the script you uploaded, and deploy the script.

    Setup Script

  6. After selecting your audience you see the following page. Take note of the script and deploy numbers in the external URL since you need them to call the RESTlet.

    Script Deployment

Import the Project

  • Go to File > Import.

  • Select Anypoint Studio Project from External Location under the Anypoint Studio parent folder.

  • Provide the root path to the demo project folder.

  • Select Mule Runtime (4.0.x EE) or later.

  • Click Finish.

  • Configure the credentials, as well as the deployed script and deploy IDs, inside the file src/main/resources/mule-app.properties.

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    
    netsuite.email=
    netsuite.password=
    netsuite.account=
    netsuite.roleId=
    netsuite.applicationId=
    netsuite.subsidiary=
    netsuite.script=
    netsuite.deploy=
    1. Open the Global Element Configuration.

    2. Click the Test Connection button to ensure there is connectivity with the sandbox.

      Test Connection is a crucial step. If you experience connectivity issues, you won’t be able to execute any part of this use case, nor make use of DataSense.

    3. A successful message should pop-up.

      Test Connection

    4. Open a browser and access the URL http://localhost:8081. You should see the application deployed:

      Demo Index

About the flows

  1. html-form-flow: Renders the HTML form with a parseTemplate component.

    Flow HMTL Form

  2. restletGet: Calls the GET function of a RESTlet.

    Flow HMTL Form

  3. restletPost: Calls the POST function of a RESTlet.

    Flow Processor 1

  4. restletDelete: Calls the DELETE function of a RESTlet.

    Flow Processor 1

See Also