Saltar para o conteúdo principal

Documentation Index

Fetch the complete documentation index at: https://developers.vendaze.com/llms.txt

Use this file to discover all available pages before exploring further.

Não existem SDKs oficiais da Vendaze. A API segue padrões REST e HTTP convencionais e funciona com qualquer cliente HTTP. Os snippets abaixo cobrem as operações mais comuns em três linguagens. Copie, adapte e use.
Todos os exemplos assumem que você já completou o fluxo OAuth e tem um access_token e refresh_token válidos. Veja Autenticação se ainda não fez isso.

Node.js

Usa a API fetch nativa (Node.js 18+). Sem dependências externas.
// Trocar um authorization code por tokens
async function exchangeCode({ code, clientId, clientSecret }) {
  const res = await fetch('https://api.vendaze.com/oauth/token', {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: new URLSearchParams({
      grant_type: 'authorization_code',
      code,
      client_id: clientId,
      client_secret: clientSecret,
    }),
  });

  if (!res.ok) {
    const { error } = await res.json();
    throw new Error(`${error.code}: ${error.message}`);
  }

  return res.json();
  // { access_token, refresh_token, token_type, expires_in, workspace_slug }
}

Python

Usa a biblioteca httpx (async). Instale com pip install httpx.
import httpx

async def exchange_code(code: str, client_id: str, client_secret: str) -> dict:
    async with httpx.AsyncClient() as client:
        res = await client.post(
            "https://api.vendaze.com/oauth/token",
            data={
                "grant_type": "authorization_code",
                "code": code,
                "client_id": client_id,
                "client_secret": client_secret,
            },
        )

    res.raise_for_status()
    return res.json()
    # { "access_token": ..., "refresh_token": ..., "workspace_slug": ... }

Go

Usa apenas a biblioteca padrão. Sem dependências externas.
package vendaze

import (
    "encoding/json"
    "fmt"
    "net/http"
    "net/url"
    "strings"
)

type TokenResponse struct {
    AccessToken   string `json:"access_token"`
    RefreshToken  string `json:"refresh_token"`
    TokenType     string `json:"token_type"`
    ExpiresIn     int    `json:"expires_in"`
    WorkspaceSlug string `json:"workspace_slug"`
}

func ExchangeCode(code, clientID, clientSecret string) (*TokenResponse, error) {
    form := url.Values{
        "grant_type":    {"authorization_code"},
        "code":          {code},
        "client_id":     {clientID},
        "client_secret": {clientSecret},
    }

    res, err := http.Post(
        "https://api.vendaze.com/oauth/token",
        "application/x-www-form-urlencoded",
        strings.NewReader(form.Encode()),
    )
    if err != nil {
        return nil, err
    }
    defer res.Body.Close()

    if res.StatusCode != http.StatusOK {
        var errBody struct {
            Error struct {
                Code    string `json:"code"`
                Message string `json:"message"`
            } `json:"error"`
        }
        json.NewDecoder(res.Body).Decode(&errBody)
        return nil, fmt.Errorf("%s: %s", errBody.Error.Code, errBody.Error.Message)
    }

    var tokens TokenResponse
    if err := json.NewDecoder(res.Body).Decode(&tokens); err != nil {
        return nil, err
    }
    return &tokens, nil
}

Recursos da comunidade

Nenhum SDK oficial existe ainda. Se você construir uma biblioteca cliente para a Vendaze, abra um pull request no repositório vendaze/vendaze-api para ser listado aqui.