How to get checkout or cart ID inside checkout-ui extension?

Hi there.

How i can obtain cart token or checkout/cart id inside extension?

import { extension, TextField } from "@shopify/ui-extensions/checkout";
export default extension("purchase.checkout.delivery-address.render-before", async (root, api) => {
    console.log('api', api);
}

I already try to find it inside api object. And got no luck.

Did you find a solution to this? I’m looking into this as well.

The solution to this is use checkoutToken

And it is only available in react extension build at the moment.

let api = useApi();
const checkoutToken = api.checkoutToken.current;
1 Like

I posted solution mate.

1 Like

Thank you! How are you using the checkout token to connect it back to the cart id from the storefront session though? I’m looking for a way to connect a checkout session to a storefront session.

Nevermind, found it - it matches the checkout_token field in the Admin REST API Order resource. Thanks!