# ZapietId

## What is the ZapietId?

The \_ZapietId is integral to our Rates functionality. At least one item in your customers basket must contain a valid \_ZapietId line item property otherwise rates will fail to generate correctly within the checkout process. &#x20;

![](https://4027567088-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFA_xQN0MxCjA_jkDq7%2F-M__swFnBTsb0hHCfSx6%2F-M__wlMldQsFx5JfuImJ%2FScreenshot%202021-05-13%20at%2014.37.38.png?alt=media\&token=dc7ba728-0b83-4769-a17f-6d6e4ec6f615)

The \_ZapietId is made up of the following three parameters:

| Parameter | Data type | Example              | Notes                                                                                                                                                                   |
| --------- | --------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| M         | string    | P                    | <p>The value can be either P, D or S. </p><p></p><p>P = pickup</p><p>D = delivery</p><p>S = shipping  </p><p></p><p><strong>Required for all orders</strong></p>        |
| L         | integer   | 1002                 | <p>The Zapiet location ID </p><p></p><p><strong>Required for pickup and delivery orders</strong></p>                                                                    |
| D         | datetime  | 2021-05-13T12:00:00Z | <p>The customers selected date and time for delivery, pickup or shipping</p><p></p><p><strong>Required for date based pickup, delivery and shipping orders</strong></p> |

## Adding the \_ZapietId to a line item

If you are using our default widget the \_ZapietId property is automatically added to your order. Should you be building your own storefront widget you can use Shopify's Cart API <https://shopify.dev/docs/themes/ajax-api/reference/cart>.&#x20;

Alternatively if you are building a mobile app or using a headless commerce solution you may prefer to use the Draft Orders API <https://shopify.dev/docs/admin-api/rest/reference/orders/draftorder>.

{% hint style="info" %}
The line item must be called \_ZapietId including the prepending underscore.&#x20;
{% endhint %}

```javascript
$.post('/cart/change.js', data);
```

## Generating the \_ZapietId

Below is a  javascript example of how you might generate a \_ZapietId.

```javascript
function getZapietId(params)
{
    var fomatted_date = '';
    if (params.date && !params.time) {
        var fomatted_date = params.date.replace(/\//g, "-");
        fomatted_date = fomatted_date + 'T00:00:00Z';
    } else if (params.date && params.start_time) {
        var fomatted_date = params.date.replace(/\//g, "-");
        fomatted_date = fomatted_date + 'T' + params.start_time + ':00Z';
    }
    return this.encodeZapietId({
        M: this.getMethodKey(params.method),
        L: (params.location_id) ? params.location_id : "",
        D: fomatted_date,
        P: ""
    });
}

function getMethodKey(method) {
    if (method == 'delivery') {
        return 'D';
    } else if (method == 'pickup') {
        return 'P';
    } else {
        return 'S';
    }
}

function encodeZapietId(params) {
    const ret = [];
    for (let d in params) {
        if (params[d]) {
            ret.push(d + '=' + params[d]);
        }
    }
    return ret.join('&');
}

const ZapietId = getZapietId({
   date: '2021-05-13',
   start_time: '10:00',
   location_id: 10001,
   method: 'pickup'
});
```
