Flex Gateway新着情報
Governance新着情報
Monitoring API Managerこの例では次の方法を示します。
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
ファイル内のログイン情報
顧客レコードを作成、取得、削除するスクリプトを作成してデプロイします。
サンプル 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"
}
javascript
アカウントの SuiteScript と NetSuite Web サービスを有効にします。
NetSuite にログインします。
[Set Up (セットアップ)] > [Company (会社)] > [Enable Features (機能の有効化)] > [SuiteCloud] をクリックします:
以前に作成したファイルをアップロードします。
[Customization (カスタマイズ)] > [Scripting (スクリプト)] > [Scripts (スクリプト)] > [New (新規)] に移動します。
スクリプトファイルを選択し、[Create Script Record (スクリプトレコードの作成)] をクリックし、[RESTlet] を選択します。
アップロードしたスクリプトの内容を使用してフォームに入力し、スクリプトをデプロイします。
次のページを表示するオーディエンスを選択します。
外部 URL に表示されているスクリプト番号とデプロイ番号を書き留めておきます。これらは、後で RESTlet をコールするために必要です。
Studio で新しい Mule プロジェクトを作成し、NetSuite に接続するためのログイン情報、デプロイしたスクリプト、デプロイ ID を設定します。
Studio で、[File (ファイル)] > [New (新規)] > [Mule Project (Mule プロジェクト)] を選択します。
Mule プロジェクトの名前を入力して、[Finish (完了)] をクリックします。
Package Explorer で、作成した Studio プロジェクトに配置されている src/main/resources/mule-app.properties
ファイルを開きます。
次の値を設定します。
netsuite.email= netsuite.password= netsuite.account= netsuite.roleId= netsuite.applicationId= netsuite.subsidiary= netsuite.script= netsuite.deploy=
javascript
netsuite.script
と netsuite.deploy
の値は、「スクリプトを作成して RESTlet としてデプロイする」の最後のステップで書き留めた値です。
NetSuite Connector を Mule プロジェクトに追加して、XML コードにコネクタの名前空間およびスキーマの場所を自動的に入力し、プロジェクトの pom.xml
ファイルに必須の連動関係を追加します。
[Mule Palette (Mule パレット)] ビューで、[(X) Search in Exchange ((X) Exchange 内を検索)] をクリックします。
[Add Modules to Project (モジュールをプロジェクトに追加)] で、検索項目に「netsuite
」と入力します。
[Available modules (使用可能なモジュール)] で、そのコネクタ名をクリックします。
[Add (追加)] をクリックします。
[Finish (完了)] をクリックします。
Studio キャンバスで Configuration XML (設定 XML) をクリックします。
<?xml version="1.0" encoding="UTF-8"?>
行の後のすべての内容を削除します。
次の XML をコピーして、<?xml version="1.0" encoding="UTF-8"?>
行の後に貼り付けます。
<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>
xml
プロジェクトを保存します。
html-form
フローでは、parseTemplate
コンポーネントを使用して HTML フォームを表示します。
restletGet
フローでは、RESTlet の GET 関数をコールします。
restletPost
フローでは、RESTlet の POST 関数をコールします。
restletDelete
フローでは、RESTlet の DELETE 関数をコールします。
アプリケーションを実行、デプロイ、確認します。
プロジェクトのキャンバスの下部にある [Global Elements (グローバル要素)] をクリックします。
[Global Configuration Elements (グローバル設定要素)] で、[NetSuite Rest config (NetSuite Rest 設定)] を選択して [Edit (編集)] をクリックします。
[Test Connection (接続をテスト)] をクリックして、Sandbox と接続されていることを確認します。
成功メッセージが表示されます。
Package Explorer でプロジェクト名をクリックし、[Run (実行)] > [Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)] をクリックします。
コンソールで、Mule is up and kicking
のメッセージを探して、アプリケーションが正常に開始されたことを確認します。
ブラウザーを開き、URL http://localhost:8081
にアクセスします。
アプリケーションがデプロイされたことを確認できます。