Sales invoice example (API Gateway models and mapping templates) - Amazon API Gateway

Sales invoice example (API Gateway models and mapping templates)

The following sections provide examples of models and mapping templates that could be used for a sample sales invoice API in API Gateway. For more information about models and mapping templates in API Gateway, see PetStore mapping template.

Original data (sales invoice example)

The following is the original JSON data for the sales invoice example:

{ "DueDate": "2013-02-15", "Balance": 1990.19, "DocNumber": "SAMP001", "Status": "Payable", "Line": [ { "Description": "Sample Expense", "Amount": 500, "DetailType": "ExpenseDetail", "ExpenseDetail": { "Customer": { "value": "ABC123", "name": "Sample Customer" }, "Ref": { "value": "DEF234", "name": "Sample Construction" }, "Account": { "value": "EFG345", "name": "Fuel" }, "LineStatus": "Billable" } } ], "Vendor": { "value": "GHI456", "name": "Sample Bank" }, "APRef": { "value": "HIJ567", "name": "Accounts Payable" }, "TotalAmt": 1990.19 }

Input model (sales invoice example)

The following is the input model that corresponds to the original JSON data for the sales invoice example:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "InvoiceInputModel", "type": "object", "properties": { "DueDate": { "type": "string" }, "Balance": { "type": "number" }, "DocNumber": { "type": "string" }, "Status": { "type": "string" }, "Line": { "type": "array", "items": { "type": "object", "properties": { "Description": { "type": "string" }, "Amount": { "type": "integer" }, "DetailType": { "type": "string" }, "ExpenseDetail": { "type": "object", "properties": { "Customer": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "Ref": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "Account": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "LineStatus": { "type": "string" } } } } } }, "Vendor": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "APRef": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "TotalAmt": { "type": "number" } } }

Input mapping template (sales invoice example)

The following is the input mapping template that corresponds to the original JSON data for the sales invoice example:

#set($inputRoot = $input.path('$')) { "DueDate": "$inputRoot.DueDate", "Balance": $inputRoot.Balance, "DocNumber": "$inputRoot.DocNumber", "Status": "$inputRoot.Status", "Line": [ #foreach($elem in $inputRoot.Line) { "Description": "$elem.Description", "Amount": $elem.Amount, "DetailType": "$elem.DetailType", "ExpenseDetail": { "Customer": { "value": "$elem.ExpenseDetail.Customer.value", "name": "$elem.ExpenseDetail.Customer.name" }, "Ref": { "value": "$elem.ExpenseDetail.Ref.value", "name": "$elem.ExpenseDetail.Ref.name" }, "Account": { "value": "$elem.ExpenseDetail.Account.value", "name": "$elem.ExpenseDetail.Account.name" }, "LineStatus": "$elem.ExpenseDetail.LineStatus" } }#if($foreach.hasNext),#end #end ], "Vendor": { "value": "$inputRoot.Vendor.value", "name": "$inputRoot.Vendor.name" }, "APRef": { "value": "$inputRoot.APRef.value", "name": "$inputRoot.APRef.name" }, "TotalAmt": $inputRoot.TotalAmt }

Transformed data (sales invoice example)

The following is one example of how the original sales invoice example JSON data could be transformed for output:

{ "DueDate": "2013-02-15", "Balance": 1990.19, "DocNumber": "SAMP001", "Status": "Payable", "Line": [ { "Description": "Sample Expense", "Amount": 500, "DetailType": "ExpenseDetail", "Customer": "ABC123 (Sample Customer)", "Ref": "DEF234 (Sample Construction)", "Account": "EFG345 (Fuel)", "LineStatus": "Billable" } ], "TotalAmt": 1990.19 }

Output model (sales invoice example)

The following is the output model that corresponds to the transformed JSON data format:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "InvoiceOutputModel", "type": "object", "properties": { "DueDate": { "type": "string" }, "Balance": { "type": "number" }, "DocNumber": { "type": "string" }, "Status": { "type": "string" }, "Line": { "type": "array", "items": { "type": "object", "properties": { "Description": { "type": "string" }, "Amount": { "type": "integer" }, "DetailType": { "type": "string" }, "Customer": { "type": "string" }, "Ref": { "type": "string" }, "Account": { "type": "string" }, "LineStatus": { "type": "string" } } } }, "TotalAmt": { "type": "number" } } }

Output mapping template (sales invoice example)

The following is the output mapping template that corresponds to the transformed JSON data format. The template variables here are based on the original, not transformed, JSON data format:

#set($inputRoot = $input.path('$')) { "DueDate": "$inputRoot.DueDate", "Balance": $inputRoot.Balance, "DocNumber": "$inputRoot.DocNumber", "Status": "$inputRoot.Status", "Line": [ #foreach($elem in $inputRoot.Line) { "Description": "$elem.Description", "Amount": $elem.Amount, "DetailType": "$elem.DetailType", "Customer": "$elem.ExpenseDetail.Customer.value ($elem.ExpenseDetail.Customer.name)", "Ref": "$elem.ExpenseDetail.Ref.value ($elem.ExpenseDetail.Ref.name)", "Account": "$elem.ExpenseDetail.Account.value ($elem.ExpenseDetail.Account.name)", "LineStatus": "$elem.ExpenseDetail.LineStatus" }#if($foreach.hasNext),#end #end ], "TotalAmt": $inputRoot.TotalAmt }