Saltar para o conteúdo
Anagen
PT EN
Pedir avaliação

Guia 2/12

Primeiros passos

Do zero à primeira resposta em quatro passos.

  1. Peça à clínica uma credencial de integração. Em Administração → Integrações a clínica cria a integração, escolhe os âmbitos (ex.: crm.leads:editar) e, se quiser, limita os endereços de origem. Recebe um client_id (ax_…) e um client_secret mostrado uma única vez — guarde-o num cofre de segredos, nunca no código.
  2. Peça um token de acesso com o fluxo OAuth 2.0 client credentials. O token vale 1 hora.
  3. Faça a primeira chamada com Authorization: Bearer <token>.
  4. Experimente sem escrever código na referência: cada operação tem a consola «Experimentar» (o token fica só no seu navegador).

Pedir o token

curl -X POST "https://anagen.pt/api/v1/oauth/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=ax_3f9c2b7e41d8a6f05c1e9b24" \
  -d "client_secret=$ANAGEN_SECRET" \
  -d "scope=crm.leads:editar agenda:ver"
<?php
$ch = curl_init('https://anagen.pt/api/v1/oauth/token');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => http_build_query([
        'grant_type'    => 'client_credentials',
        'client_id'     => getenv('ANAGEN_CLIENT_ID'),
        'client_secret' => getenv('ANAGEN_SECRET'),
    ]),
]);
$token = json_decode(curl_exec($ch), true)['access_token'];
curl_close($ch);
const resposta = await fetch('https://anagen.pt/api/v1/oauth/token', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body: new URLSearchParams({
    grant_type: 'client_credentials',
    client_id: process.env.ANAGEN_CLIENT_ID,
    client_secret: process.env.ANAGEN_SECRET,
  }),
});
const { access_token: token, expires_in } = await resposta.json();
import os, requests

r = requests.post("https://anagen.pt/api/v1/oauth/token", data={
    "grant_type": "client_credentials",
    "client_id": os.environ["ANAGEN_CLIENT_ID"],
    "client_secret": os.environ["ANAGEN_SECRET"],
}, timeout=30)
r.raise_for_status()
token = r.json()["access_token"]
using var http = new HttpClient();
var resposta = await http.PostAsync("https://anagen.pt/api/v1/oauth/token", new FormUrlEncodedContent(new Dictionary<string, string>
{
    ["grant_type"] = "client_credentials",
    ["client_id"] = Environment.GetEnvironmentVariable("ANAGEN_CLIENT_ID")!,
    ["client_secret"] = Environment.GetEnvironmentVariable("ANAGEN_SECRET")!,
}));
using var doc = System.Text.Json.JsonDocument.Parse(await resposta.Content.ReadAsStringAsync());
var token = doc.RootElement.GetProperty("access_token").GetString();

Primeira chamada

curl "https://anagen.pt/api/v1/r/leads?por_pagina=5&ordem=criado_em:desc" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept-Language: pt-PT"
{
  "ok": true,
  "dados": [
    {"id": 412, "nome": "Rita Matos", "origem": "site", "origem_rotulo": "Site", "criado_em": "2026-10-28T09:41:00+00:00"}
  ],
  "meta": {"pagina": 1, "por_pagina": 5, "total": 128}
}

Descarregue a especificação OpenAPI ou a coleção Postman (com o pedido de token pronto e as variáveis base_url, client_id e client_secret).