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.

The _ZapietId is made up of the following three parameters:

Parameter

Data type

Example

Notes

M

string

P

The value can be either P, D or S.

P = pickup

D = delivery

S = shipping

Required for all orders

L

integer

1002

The Zapiet location ID

Required for pickup and delivery orders

D

datetime

2021-05-13T12:00:00Z

The customers selected date and time for delivery, pickup or shipping

Required for date based pickup, delivery and shipping orders

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.

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.

The line item must be called _ZapietId including the prepending underscore.

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

Generating the _ZapietId

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

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

Last updated