---
schema_version: "1"
id: 049b22433c2ac6683d4fbbb65dc2f891a258044255e7ecf52b01704d5512cb99
title: NetSuite RESTlet のコールの例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/netsuite-restlet-call-restlets-example.md
canonical_url: https://docs.mulesoft.com/jp/netsuite-restlet-connector/latest/netsuite-restlet-call-restlets-example
source_site: docs.mulesoft.com
content_type: documentation
content_hash: bcec94e5cdd3cf1384b91794313f2d37070e2e7b32afa9f33b935b2778baa045
description: MuleSoft Documentation Site
release: "1.0"
latest: true
---
# NetSuite RESTlet のコールの例

この例では次の方法を示します。

- NetSuite インスタンスにデプロイされた NetSuite RESTlets をコールして顧客レコードを作成、取得、削除するスクリプトを作成する
- RESTlet スクリプトをデプロイする
- NetSuite に接続してアプリケーションをデプロイするようにアプリケーションのプロパティを設定する

## [](#始める前に)始める前に

この例を実行するには、以下が必要です。

- Java 8、11、または 17
- Anypoint Studio 7.0.x
- Mule 4.2.1 以降
- DataWeave 2.0
- NetSuite インスタンスへのアクセス権と ​`mule-app.properties`​ ファイル内のログイン情報

## [](#deploy-a-script-as-restlet)スクリプトを作成して RESTlet としてデプロイする

顧客レコードを作成、取得、削除するスクリプトを作成してデプロイします。

1. サンプル JavaScript スクリプトを作成します。
    
    ```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. アカウントの SuiteScript と NetSuite Web サービスを有効にします。
    
    1. NetSuite にログインします。
    2. **\[Set Up (セットアップ)\] > \[Company (会社)\] > \[Enable Features (機能の有効化)\] > \[SuiteCloud\]**​ をクリックします:
        
        ![SuiteScript の有効化ページ](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-enable-suitescript.png)
3. [以前に作成した](#deploy-a-script-as-restlet)​ファイルをアップロードします。
    
    1. **\[Customization (カスタマイズ)\] > \[Scripting (スクリプト)\] > \[Scripts (スクリプト)\] > \[New (新規)\]**​ に移動します。
    2. スクリプトファイルを選択し、​**\[Create Script Record (スクリプトレコードの作成)\]**​ をクリックし、​**\[RESTlet\]**​ を選択します。
        
        ![スクリプト種別の選択ページ](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-script-type.png)
4. アップロードしたスクリプトのコンテンツを使用してフォームに入力し、スクリプトをデプロイします。
    
    ![スクリプトの設定ページ](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-setup-script.png)
5. 次のページを表示するオーディエンスを選択します。
    
    ![スクリプトのデプロイページ](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-script-deployment.png)
6. 外部 URL に表示されているスクリプト番号とデプロイ番号を書き留めておきます。これらは、後で RESTlet をコールするために必要です。

## [](#mule-プロジェクトを作成する)Mule プロジェクトを作成する

Studio で新しい Mule プロジェクトを作成し、NetSuite に接続するためのログイン情報、デプロイしたスクリプト、デプロイ ID を設定します。

1. Studio で、​**\[File (ファイル)\] > \[New (新規)\] > \[Mule Project (Mule プロジェクト)\]**​ を選択します。
2. Mule プロジェクトの名前を入力して、​**\[Finish (完了)\]**​ をクリックします。
3. **Package Explorer**​ で、作成した Studio プロジェクトに配置されている ​`src/main/resources/mule-app.properties`​ ファイルを開きます。
4. 次の値を設定します。
    
    ```javascript
    netsuite.email=
    netsuite.password=
    netsuite.account=
    netsuite.roleId=
    netsuite.applicationId=
    netsuite.subsidiary=
    netsuite.script=
    netsuite.deploy=
    ```
    
    `netsuite.script`​ と ​`netsuite.deploy`​ の値は、​[「スクリプトを作成して RESTlet としてデプロイする」](#deploy-a-script-as-restlet)​の最後のステップで書き留めた値です。

## [](#add-connector-to-project)コネクタを Mule プロジェクトに追加する

NetSuite Connector を Mule プロジェクトに追加して、XML コードにコネクタの名前空間およびスキーマの場所を自動的に入力し、プロジェクトの ​`pom.xml`​ ファイルに必須の連動関係を追加します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[(X) Search in Exchange ((X) Exchange 内を検索)\]**​ をクリックします。
2. **\[Add Modules to Project (モジュールをプロジェクトに追加)\]**​ で、検索項目に「​`netsuite`​」と入力します。
3. **\[Available modules (使用可能なモジュール)\]**​ で、そのコネクタ名をクリックします。
4. **\[Add (追加)\]**​ をクリックします。
5. **\[Finish (完了)\]**​ をクリックします。

## [](#アプリケーションフローを作成する)アプリケーションフローを作成する

1. Studio キャンバスで ​**Configuration XML (設定 XML)**​ をクリックします。
2. `<?xml version="1.0" encoding="UTF-8"?>`​ 行の後のすべてのコンテンツを削除します。
3. 次の XML をコピーして、​`<?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. プロジェクトを保存します。

### [](#フローについて)フローについて

1. `html-form`​ フローでは、​`parseTemplate`​ コンポーネントを使用して HTML フォームを表示します。
    
    ![HMTL フォーム Studio フロー](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-html-form-flow.png)
2. `restletGet`​ フローでは、RESTlet の GET 関数をコールします。
    
    ![Restlet Get Studio フロー](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-restlet-get.png)
3. `restletPost`​ フローでは、RESTlet の POST 関数をコールします。
    
    ![Restlet Post Studio フロー](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-restlet-post.png)
4. `restletDelete`​ フローでは、RESTlet の DELETE 関数をコールします。
    
    ![Restlet Delete Studio フロー](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-restlet-delete.png)

## [](#アプリケーションを実行する)アプリケーションを実行する

アプリケーションを実行、デプロイ、確認します。

1. プロジェクトのキャンバスの下部にある ​**\[Global Elements (グローバル要素)\]**​ をクリックします。
2. **\[Global Configuration Elements (グローバル設定要素)\]**​ で、​**\[NetSuite Rest config (NetSuite Rest 設定)\]**​ を選択して ​**\[Edit (編集)\]**​ をクリックします。
3. **\[Test Connection (接続をテスト)\]**​ をクリックして、Sandbox と接続されていることを確認します。
    
    成功メッセージが表示されます。
    
    ![\[Test connection successful (テスト接続成功)\] メッセージ](_images/netsuite-demo-connection-test.png)
4. **Package Explorer**​ でプロジェクト名をクリックし、​**\[Run (実行)\] > \[Run As (別のユーザーとして実行)\] > \[Mule Application (Mule アプリケーション)\]**​ をクリックします。  
    コンソールで、​`Mule is up and kicking`​ のメッセージを探して、アプリケーションが正常に開始されたことを確認します。
5. ブラウザーを開き、URL ​`http://localhost:8081`​ にアクセスします。  
    アプリケーションがデプロイされたことを確認できます。
    
    ![デモページ](/mulesoft/current/ja-jp/netsuite-restlet-connector/latest/_images/netsuite-demo-main-page.png)

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [NetSuite Connector の概要](https://docs.mulesoft.com/jp/netsuite-restlet-connector/latest/)
- [NetSuite Connector リファレンス](https://docs.mulesoft.com/jp/netsuite-restlet-connector/latest/netsuite-restlet-connector-reference)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)