# Order data extension

An order data extension is an object that lets you specify any key-value pairs you want. Order data extensions are optional and enable your organization to capture more robust information about your orders.

 To get started with this API, create a data extension for the order you previously created.

## Create an order data extension

 - [POST /v2.1/orders/{orderRef}/extensions/{dataExtensionName}](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/createorderdataextension.md): Creates an order data extension. 

 To avoid creating key-value pairs that already exist in the data extension for an order, first retrieve all the data extensions for an order to check that the keys you intend to create are unique. 

 ### Creating the request body 
 In the request body, you must provide one object. This object represents the data extension. Note the following about the object: 

 - Can contain primitive values only. You cannot nest objects. If you need to group key-value pairs, use prefixes for the key names. 
 - Can contain a maximum of 100 key-value pairs. 
 - The key-value pairs you include in the object become the extension data. For example, if you include "firstTimeOrder": true in the object, First Time Order with the value of true becomes extension data. 
 - Supported data types for the values: 
   - string, for example "level2" 
   - boolean, for example true 
   - integer, for example 9 
   - floating-point number, for example 99.9 

 #### Naming keys 
 The keys you enter in the request body must be: 
 - Alphanumeric A-Z,a-z,0-9] as per the [JSON RFC 7159 specification. 
 - In camel case. 

 ### Example request body 
 Here's an example request body: 
 
{ 
 "firstTimeOrder": true, 
 "storeLocation": "London", 
 "totalUnits": 8, 
 "totalDiscount": "20%"
 }
 
 This creates four key-value pairs for the order.

## Retrieve an order data extension

 - [GET /v2.1/orders/{orderRef}/extensions/{dataExtensionName}](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/retrieveorderdataextension.md): Retrieves a data extension for an order.

## Update an order data extension

 - [PUT /v2.1/orders/{orderRef}/extensions/{dataExtensionName}](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/putorderdataextension.md): Fully updates a data extension for an order, replacing the entire resource including all the key-value pairs with the data you send in the request.

To update certain key-value pairs only, use the Partially update a data extension endpoint instead.

## Partially update an order data extension

 - [PATCH /v2.1/orders/{orderRef}/extensions/{dataExtensionName}](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/updateorderdataextension.md): Partially updates a data extension for an order, replacing only those key-value pairs in the resource that you provide in the request.

## Delete an order data extension

 - [DELETE /v2.1/orders/{orderRef}/extensions/{dataExtensionName}](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/deleteorderdataextension.md): Deletes the data extension for an order, including all the key-value pairs in the data extension.

To delete certain key-value pairs only, use the Delete key-value pairs from a data extension endpoint instead.

## Delete key-value pairs from an order data extension

 - [DELETE /v2.1/orders/{orderRef}/extensions/{dataExtensionName}/fields](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/deleteorderdataextensionfields.md): Deletes the key-value pairs you provide in the name query parameter from a data extension for an order.

For example, if your data extension contains the firstTimeOrder and storeLocation keys, you can delete both keys and their values by making the following request:



 {baseURL}/v2.1/orders/{orderRef}/extensions/{dataExtensionName}/fields?name=firstTimeOrder|storeLocation

If you don't provide the query parameter, this operation will empty the data extension: the data extension itself will not be deleted, but all the key-value pairs in it will.

## Retrieve the URL for an order's data extension

 - [GET /v2.1/orders/{orderRef}/extensions](https://api-docs.sitecore.com/cdp/order-rest-api/order-data-extension/retrieveorderdataextensions.md): Retrieves the URL for the order's data extension. This lets you check if the data extension exists.

