Skip to main content
GET
/
timeline
Listar Timeline
curl --request GET \
  --url https://api.example.com/timeline
{
  "items": [
    {
      "id": "evt_001",
      "type": "purchase",
      "title": "Compra registrada",
      "description": "Você ganhou 150 pontos",
      "points": 150,
      "empresa": {
        "id": "emp_123",
        "name": "Pizzaria Exemplo",
        "logo_url": "https://..."
      },
      "metadata": {
        "nfce_id": "nfce_456",
        "valor_total": 75.00
      },
      "created_at": "2024-06-20T19:30:00Z"
    },
    {
      "id": "evt_002",
      "type": "reward",
      "title": "Prêmio resgatado",
      "description": "Pizza Margherita Grande",
      "points": -200,
      "empresa": {
        "id": "emp_123",
        "name": "Pizzaria Exemplo",
        "logo_url": "https://..."
      },
      "metadata": {
        "reward_uid": "rwd_789",
        "product_name": "Pizza Margherita Grande"
      },
      "created_at": "2024-06-18T14:00:00Z"
    },
    {
      "id": "evt_003",
      "type": "referral",
      "title": "Indicação convertida",
      "description": "Maria Santos se cadastrou usando seu link",
      "points": 100,
      "empresa": null,
      "metadata": {
        "referred_name": "Maria Santos",
        "referral_id": "ref_012"
      },
      "created_at": "2024-06-15T10:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 45,
    "total_pages": 3,
    "has_next": true,
    "has_prev": false
  }
}

Listar Timeline

Retorna o feed de atividades do usuário, incluindo compras, rewards resgatados, indicações e interações.

Query Parameters

page
integer
default:1
Número da página (paginação)
limit
integer
default:20
Itens por página (máximo 50)
empresa_id
string
Filtrar por empresa específica
type
string
Filtrar por tipo de evento: purchase, reward, referral, interaction

Request

curl -X GET "https://api.indiqai.com/api/v1/timeline?page=1&limit=20" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Response

{
  "items": [
    {
      "id": "evt_001",
      "type": "purchase",
      "title": "Compra registrada",
      "description": "Você ganhou 150 pontos",
      "points": 150,
      "empresa": {
        "id": "emp_123",
        "name": "Pizzaria Exemplo",
        "logo_url": "https://..."
      },
      "metadata": {
        "nfce_id": "nfce_456",
        "valor_total": 75.00
      },
      "created_at": "2024-06-20T19:30:00Z"
    },
    {
      "id": "evt_002",
      "type": "reward",
      "title": "Prêmio resgatado",
      "description": "Pizza Margherita Grande",
      "points": -200,
      "empresa": {
        "id": "emp_123",
        "name": "Pizzaria Exemplo",
        "logo_url": "https://..."
      },
      "metadata": {
        "reward_uid": "rwd_789",
        "product_name": "Pizza Margherita Grande"
      },
      "created_at": "2024-06-18T14:00:00Z"
    },
    {
      "id": "evt_003",
      "type": "referral",
      "title": "Indicação convertida",
      "description": "Maria Santos se cadastrou usando seu link",
      "points": 100,
      "empresa": null,
      "metadata": {
        "referred_name": "Maria Santos",
        "referral_id": "ref_012"
      },
      "created_at": "2024-06-15T10:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 45,
    "total_pages": 3,
    "has_next": true,
    "has_prev": false
  }
}

Tipos de Eventos

Compra via NFCeRegistrada quando o usuário escaneia uma nota fiscal.
{
  "type": "purchase",
  "metadata": {
    "nfce_id": "uuid",
    "valor_total": 75.00,
    "items_count": 3
  }
}

Cache

A timeline é cacheada por 5 minutos. Após criar novos eventos (compras, resgates), o cache é invalidado automaticamente.

Uso no Frontend

import { useInfiniteQuery } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';

export function useTimeline() {
  return useInfiniteQuery({
    queryKey: ['timeline'],
    queryFn: async ({ pageParam = 1 }) => {
      const { data } = await apiClient.get('/timeline', {
        params: { page: pageParam, limit: 20 }
      });
      return data;
    },
    getNextPageParam: (lastPage) => 
      lastPage.pagination.has_next 
        ? lastPage.pagination.page + 1 
        : undefined
  });
}