---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Product Order Open API Developer Guide

# Product Order Open API Developer Guide {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

Use the Product Order Open API to create, update, and retrieve product order information.

This developer guide provides information on how to extend the
[Product Order Open API](https://servicenow-prod.fluidtopics.net/lU3_sIIHvtqhkTfEEUFOCw#tmf622_product_ordering-api "The Product Order Open API provides endpoints that enable a standardized mechanism for placing product orders.") to make various
customizations.

## Extending the Product Order Open API {#ariaid-title2}

The Product Order Open API can be extended by editing script
includes.  
These script includes should only be edited with an understanding of the consequences of the changes.

* TMFProductOrderAPIUtil: Contains functions to handle POST requests.
* TMFProductOrderGetAPIUtil: Contains functions to handle GET requests.
* ProductOrderExtensionOOB: Contains helper functions that support functions in TMFProductOrderAPIUtil and TMFProductOrderGetAPIUtil.
* ProductOrderProcessor: An empty script include file. Use this file to define any functions that you want to override from ProductOrderExtensionOOB.
{#extend-product-order-api__ul_d5h_lhr_wpb}

Extend the Product Order Open API to make the following customizations.

### Required parameters {#extend-product-order-api__section_nmk_lbt_prb}

To change which request body parameters are required or not required to create a product order, override the function `getProductOrderSchema()` contained in the ProductOrderExtensionOOB script
include.

The function `getProductOrderSchema()` reads the schema from the TMFOrderAPIConstants script include. TMFOrderAPIConstants is protected and can't be edited, so you can't
just update the schema. Instead, a new schema must be read from a different file. You can override `getProductOrderSchema()` to read a new schema. To override `getProductOrderSchema()`, write a
function with the same name in the ProductOrderProcessor script include. The new function in ProductOrderProcessor will be called by TMFProductOrderAPIUtil to
replace the default `getProductOrderSchema()` function in ProductOrderExtensionOOB.  
In this example, `getProductOrderSchema()` returns a custom schema that is defined in a new constant file.

    // 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'
    });

### Request body validation {#extend-product-order-api__section_hr2_pbt_prb}

To perform additional validation on the request body, override ProductOrderExtensionOOB functions. ProductOrderExtensionOOB contains the following four helper functions that return `true` by default.

* `validatePostRequest()` - Called by `processCreateOrder()` in TMFProductOrderAPIUtil.
* `validateProductObj()` - Called by `processCreateOrder()` in TMFProductOrderAPIUtil.
* `validateRelatedPartyObj()` - Called by `processCreateOrder()` in TMFProductOrderAPIUtil.
* `validateGetRequest()` - Called by `processGetOrder()` in TMFProductOrderGetAPIUtil.

{#extend-product-order-api__ul_khg_llx_wpb}If a helper function returns `false`, it stops the API operation. To apply custom validation, override ProductOrderExtensionOOB helper functions by creating functions with identical names and parameters in ProductOrderProcessor. These new ProductOrderProcessor functions will be called by TMFProductOrderAPIUtil and TMFProductOrderGetAPIUtil to replace the default ProductOrderExtensionOOB helper functions.  
In this example, a function in ProductOrderProcessor overrides a default function in ProductOrderExtensionOOB to perform validation on the productOrderItem attribute.

    // 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'
    });

### Additional REST operations {#extend-product-order-api__section_uqn_rbt_prb}

To create additional operations beyond the existing GET and POST operations, [create additional scripted REST resources](https://servicenow-prod.fluidtopics.net/UgGBneINsjR8NnEQQhXCwA "Create a scripted REST API resource to define the HTTP method, the processing script, and to override settings from the parent service.") for the Product Order Open API. The logic of the new scripted REST resources should be consistent with the existing operations. Define functions for the new operations in a new script include.

### Field mapping {#extend-product-order-api__section_bs3_tbt_prb}

When creating records, the API maps request body parameters to record fields. When retrieving
records, the API maps record fields to response object attributes.  
ProductOrderExtensionOOB contains the following functions to map a POST request body to a GlideRecord.

* `transformOrderGr()`
* `transformOrdLineItemGr()`
* `getLineItemPrice()`
* `transformPriceOrderTypeAndState()`
* `transformCustLineItmContact()`
* `transformOrderItemChar()`
{#extend-product-order-api__ul_krb_r4x_wpb}  
ProductOrderExtensionOOB contains the following functions to map a GlideRecord to a response object for GET or POST requests.

* `transformPostOrderResponse()`
* `transformGetOrderResponse()`
* `transformProductObj()`
* `transformRelatedPartyCustomerLineItem()`
* `transformOrderItemRelationship()`
* `transformGetOrdLineItmResponse()`
* `transformProductCharacteristics()`
* `transformProductSpecification()`

{#extend-product-order-api__ul_qqk_zfz_wpb}Customize field mappings to add and retrieve data for additional fields, or to change the default mappings for fields. To customize the field mappings, override ProductOrderExtensionOOB mapping functions by creating functions with identical names and parameters in ProductOrderProcessor. These new ProductOrderProcessor functions will be used by TMFProductOrderAPIUtil and TMFProductOrderGetAPIUtil to replace the default ProductOrderExtensionOOB mapping functions.  
In this example, two functions in ProductOrderProcessor override the default functions in ProductOrderExtensionOOB to create mappings for the external_id and sys_id fields.

    // 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'
    });


