製品注文オープン API 開発者ガイド
製品注文オープン API を使用して、製品の注文情報を作成、更新、取得します。
この開発者ガイドでは、製品注文オープン API を拡張してさまざまなカスタマイズを行う方法について説明します。
製品注文オープン API の拡張
製品注文オープン API は、スクリプトインクルードを編集することによって拡張できます。
- TMFProductOrderAPIUtil:POST 要求を処理する関数が含まれています。
- TMFProductOrderGetAPIUtil:GET 要求を処理する関数が含まれています。
- ProductOrderExtensionOOB:TMFProductOrderAPIUtil と TMFProductOrderGetAPIUtil の関数をサポートするヘルパー関数が含まれています。
- ProductOrderProcessor:空のスクリプトインクルードファイル。このファイルを使用して、 ProductOrderExtensionOOB からオーバーライドする関数を定義します。
製品注文オープン API を拡張して、次のカスタマイズを行います。
必要なパラメーター
製品注文の作成に必須または不要な要求本文パラメーターを変更するには、ProductOrderExtensionOOB スクリプトインクルードに含まれる関数 getProductOrderSchema() を上書きします。
関数 getProductOrderSchema() は、 TMFOrderAPIConstants スクリプトインクルードからスキーマを読み取ります。TMFOrderAPIConstants は保護されており、編集できないため、スキーマを更新することはできません。代わりに、別のファイルから新しいスキーマを読み取る必要があります。getProductOrderSchema() をオーバーライドして、新しいスキーマを読み取ることができます。getProductOrderSchema() をオーバーライドするには、ProductOrderProcessor スクリプトインクルードに同じ名前の関数を記述します。ProductOrderProcessor の新しい関数は TMFProductOrderAPIUtil によって呼び出され、ProductOrderExtensionOOB のデフォルトの getProductOrderSchema() 関数を置き換えます。
getProductOrderSchema() は、新しい定数ファイルで定義されているカスタムスキーマを返します。 // ProductOrderProcessor
var ProductOrderProcessor = Class.create();
ProductOrderProcessor.prototype = Object.extendsObject(ProductOrderExtensionOOB, {
// Define overriding functions here
// Function name and parameters must be identical to the function it overrides
getProductOrderSchema: function() {
//Define your own custom schema in a new constant file
return JSON.parse(Constants.SCHEMA.CREATE_PRODUCT_ORDER);
},
type: 'ProductOrderProcessor'
});要求本文の検証
true を返す次の 4 つのヘルパー関数が含まれています。validatePostRequest()- TMFProductOrderAPIUtil のprocessCreateOrder()によって呼び出されます。validateProductObj()- TMFProductOrderAPIUtil のprocessCreateOrder()によって呼び出されます。validateRelatedPartyObj()- TMFProductOrderAPIUtil のprocessCreateOrder()によって呼び出されます。validateGetRequest()- TMFProductOrderGetAPIUtil のprocessGetOrder()によって呼び出されます。
false を返すと、API の操作が停止します。カスタム検証を適用するには、ProductOrderProcessor で同じ名前とパラメーターを持つ関数を作成して、ProductOrderExtensionOOB ヘルパー関数をオーバーライドします。これらの新しい ProductOrderProcessor 関数は、デフォルトの ProductOrderExtensionOOB ヘルパー関数を置き換えるために、TMFProductOrderAPIUtil と TMFProductOrderGetAPIUtil によって呼び出されます。// ProductOrderProcessor
var ProductOrderProcessor = Class.create();
ProductOrderProcessor.prototype = Object.extendsObject(ProductOrderExtensionOOB, {
// Define overriding functions here
// Function name and parameters must be identical to the function it overrides
validatePostRequest: function(orderObject, details) {
// Returning false terminates the POST request
// Make sure to push error message in details array in case of error
if (gs.nil(orderObject.productOrderItem)) {
details.push(new TMFCommonOrderAPIUtil().getErrorDetailsObj(TMFOrderAPIConstants.MESSAGES.MISSING_ORDER_ITEM, '/'));
return false;
}
return true;
},
type: 'ProductOrderProcessor'
});追加の REST 操作
既存の GET および POST 操作以外に追加の操作を作成するには、Product Order Open API 用の追加のスクリプト化された REST リソースを作成します。新しいスクリプト化済み REST リソースのロジックは、既存の操作と一致する必要があります。新しいスクリプトインクルードで新しい操作の関数を定義します。
フィールドマッピング
レコードを作成する際には、API は要求本文パラメーターをレコードのフィールドにマッピングします。レコードを取得する際には、API はレコードのフィールドを応答オブジェクトの属性にマッピングします。
transformOrderGr()transformOrdLineItemGr()getLineItemPrice()transformPriceOrderTypeAndState()transformCustLineItmContact()transformOrderItemChar()
transformPostOrderResponse()transformGetOrderResponse()transformProductObj()transformRelatedPartyCustomerLineItem()transformOrderItemRelationship()transformGetOrdLineItmResponse()transformProductCharacteristics()transformProductSpecification()
// ProductOrderProcessor
var ProductOrderProcessor = Class.create();
ProductOrderProcessor.prototype = Object.extendsObject(ProductOrderExtensionOOB, {
// Define overriding functions here
// Function name and parameters must be identical to the function it overrides
transformOrderGr: function(requestObject, orderGr) {
orderGr.external_id = requestObject.externalId;
return orderGr;
},
transformPostOrderResponse: function(orderObject, orderGr) {
orderObject.id = orderGr.getValue('sys_id');
return orderObject;
},
type: 'ProductOrderProcessor'
});