checkoutStart
Mutation Shop API — POST https://shop.api.gist.link/graphql
Begin checkout for a cart: compute totals (tax/discount) in integer minor units, create a pending Order snapshotting the cart lines, open a pay checkout session (requiresShipping + parcels + sourceRef shop:order:<uuid>) and return the hosted checkout URL. Shipping is NOT computed here: pay’s checkout collects the address and the shipping rate before payment. shippingAddress is optional and only used to pick the tax rate. PUBLIC.
Required permission
Section titled “Required permission”shop:mutation:checkoutStartThe calling IAM key must hold this permission (or a wildcard that covers it:
shop:mutation:* or shop:*) and the access token
must have been minted with audience=shop. See
Permissions.
Definition
Section titled “Definition”type Mutation { checkoutStart(cartToken: String!, email: String!, shippingAddress: JSON): CheckoutStartResult!}Arguments
Section titled “Arguments”| Argument | Type | Required | Description |
|---|---|---|---|
cartToken |
String! |
Yes | — |
email |
String! |
Yes | — |
shippingAddress |
JSON |
No | — |
Returns
Section titled “Returns”CheckoutStartResult! — see the Shop types reference.
Example
Section titled “Example”curl https://shop.api.gist.link/graphql \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H 'Content-Type: application/json' \ -d @- <<'JSON' { "query": "mutation CheckoutStart($cartToken: String!, $email: String!, $shippingAddress: JSON) { checkoutStart(cartToken: $cartToken, email: $email, shippingAddress: $shippingAddress) { checkout_url checkout_session_token } }", "variables": { "cartToken": "example", "email": "ada@example.com", "shippingAddress": {} } }JSONconst response = await fetch('https://shop.api.gist.link/graphql', { method: 'POST', headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ query: `mutation CheckoutStart($cartToken: String!, $email: String!, $shippingAddress: JSON) { checkoutStart(cartToken: $cartToken, email: $email, shippingAddress: $shippingAddress) { checkout_url checkout_session_token } }`, variables: { "cartToken": "example", "email": "ada@example.com", "shippingAddress": {} }, }),});
const { data, errors } = await response.json();if (errors) throw new Error(errors[0].message);console.log(data);<?php
$payload = json_encode([ 'query' => 'mutation CheckoutStart($cartToken: String!, $email: String!, $shippingAddress: JSON) { checkoutStart(cartToken: $cartToken, email: $email, shippingAddress: $shippingAddress) { checkout_url checkout_session_token } }', 'variables' => json_decode('{"cartToken":"example","email":"ada@example.com","shippingAddress":{}}', true),]);
$ch = curl_init('https://shop.api.gist.link/graphql');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $accessToken, 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => $payload,]);
$result = json_decode(curl_exec($ch), true);curl_close($ch);
if (isset($result['errors'])) { throw new RuntimeException($result['errors'][0]['message']);}
var_dump($result['data']);import requests
response = requests.post( "https://shop.api.gist.link/graphql", headers={ "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", }, json={ "query": """mutation CheckoutStart($cartToken: String!, $email: String!, $shippingAddress: JSON) { checkoutStart(cartToken: $cartToken, email: $email, shippingAddress: $shippingAddress) { checkout_url checkout_session_token } }""", "variables": { "cartToken": "example", "email": "ada@example.com", "shippingAddress": {} }, }, timeout=30,)body = response.json()if body.get("errors"): raise RuntimeError(body["errors"][0]["message"])print(body["data"])