API REST v1

Autentique com Authorization: Bearer sk_live_… (gere em Integrações → API). Limite: 120 requisições por minuto por chave.

Listar pedidos

GET /api/v1/orders?status=paid&limit=50&cursor=…

curl https://app.guava.com.br/api/v1/orders?status=paid \
  -H "Authorization: Bearer sk_live_xxx"

{ "data": [ { "id": "…", "code": "GVREGW8JYR", "status": "paid", "total_cents": 30780, "customer": { … }, "items": [ … ] } ], "next_cursor": "…" }

Listar produtos e links

GET /api/v1/products

{ "data": [ { "id": "…", "name": "Método Foco Total", "offers": [ { "code": "foco-total", "price_cents": 29700, "checkout_url": "https://…/c/foco-total" } ] } ] }

Use para Shopify, WooCommerce, CRMs ou qualquer loja: envie os itens e redirecione o cliente para a checkout_url.

POST /api/v1/checkout-links

curl -X POST https://app.guava.com.br/api/v1/checkout-links \
  -H "Authorization: Bearer sk_live_xxx" -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "name": "Camiseta Preta M", "price_cents": 8990, "quantity": 2, "image_url": "https://…/camiseta.jpg" },
      { "name": "Boné", "price_cents": 4990, "quantity": 1 }
    ],
    "type": "physical",
    "external_id": "woo_12345",
    "redirect_url": "https://sualoja.com.br/obrigado",
    "pix_discount_percent": 5
  }'

→ 201 { "checkout_url": "https://app.guava.com.br/c/ab12cd34?ext=woo_12345", "offer_code": "ab12cd34", "total_cents": 22970 }

WooCommerce (exemplo)

functions.php do tema

add_action('template_redirect', function () {
  if (!is_checkout() || is_wc_endpoint_url()) return;
  $items = [];
  foreach (WC()->cart->get_cart() as $item) {
    $items[] = ['name' => $item['data']->get_name(), 'price_cents' => (int) round($item['data']->get_price() * 100), 'quantity' => $item['quantity']];
  }
  $res = wp_remote_post('https://app.guava.com.br/api/v1/checkout-links', [
    'headers' => ['Authorization' => 'Bearer ' . GUAVA_API_KEY, 'Content-Type' => 'application/json'],
    'body' => wp_json_encode(['items' => $items, 'external_id' => 'woo_' . WC()->session->get_customer_id()]),
  ]);
  $body = json_decode(wp_remote_retrieve_body($res), true);
  if (!empty($body['checkout_url'])) { wp_redirect($body['checkout_url']); exit; }
});

Erros

{ "error": { "status": 401, "message": "Chave de API inválida ou revogada." } }