> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alana.shopping/llms.txt
> Use this file to discover all available pages before exploring further.

# Buscando Feeds

> Recupere feeds de produtos para Google Shopping, Meta Commerce e OpenAI Commerce.

## Endpoint

```
GET /api/v1/feeds/{platform}
```

**Parâmetros de caminho:**

| Parâmetro  | Valores                    |
| ---------- | -------------------------- |
| `platform` | `google`, `meta`, `openai` |

## Requisição Básica

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://app.alana.shopping/api/v1/feeds/google" \
    -H "X-API-Key: sk_live_sua_chave_api"
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    "https://app.alana.shopping/api/v1/feeds/google",
    { headers: { "X-API-Key": "sk_live_sua_chave_api" } }
  );
  const xml = await res.text();
  ```

  ```python Python theme={null}
  import requests

  res = requests.get(
      "https://app.alana.shopping/api/v1/feeds/google",
      headers={"X-API-Key": "sk_live_sua_chave_api"},
  )
  print(res.text)
  ```
</CodeGroup>

## Streaming NDJSON

Para catálogos grandes, use NDJSON para processar produtos um de cada vez:

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://app.alana.shopping/api/v1/feeds/google" \
    -H "X-API-Key: sk_live_sua_chave_api" \
    -H "Accept: application/x-ndjson"
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    "https://app.alana.shopping/api/v1/feeds/google",
    {
      headers: {
        "X-API-Key": "sk_live_sua_chave_api",
        Accept: "application/x-ndjson",
      },
    }
  );

  const reader = res.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const lines = decoder.decode(value).split("\n").filter(Boolean);
    for (const line of lines) {
      const product = JSON.parse(line);
      console.log(product.id, product.title);
    }
  }
  ```

  ```python Python theme={null}
  import requests, json

  with requests.get(
      "https://app.alana.shopping/api/v1/feeds/google",
      headers={
          "X-API-Key": "sk_live_sua_chave_api",
          "Accept": "application/x-ndjson",
      },
      stream=True,
  ) as res:
      for line in res.iter_lines():
          if line:
              product = json.loads(line)
              print(product["id"], product["title"])
  ```
</CodeGroup>

## ETag e Feeds Delta

Use `ETag` para polling eficiente — baixe um novo feed apenas quando o conteúdo mudar:

<CodeGroup>
  ```bash cURL theme={null}
  # Primeira requisição — salve o ETag
  curl -I "https://app.alana.shopping/api/v1/feeds/google" \
    -H "X-API-Key: sk_live_sua_chave_api"
  # ETag: "abc123def456"

  # Requisições subsequentes — pule o download se não mudou
  curl "https://app.alana.shopping/api/v1/feeds/google" \
    -H "X-API-Key: sk_live_sua_chave_api" \
    -H "If-None-Match: \"abc123def456\""
  # Retorna 304 Not Modified se o feed não mudou
  ```

  ```javascript JavaScript theme={null}
  let etag = null;

  async function pollFeed() {
    const headers = { "X-API-Key": "sk_live_sua_chave_api" };
    if (etag) headers["If-None-Match"] = etag;

    const res = await fetch(
      "https://app.alana.shopping/api/v1/feeds/google",
      { headers }
    );

    if (res.status === 304) return null;

    etag = res.headers.get("ETag");
    return await res.text();
  }
  ```

  ```python Python theme={null}
  import requests

  etag = None

  def poll_feed():
      global etag
      headers = {"X-API-Key": "sk_live_sua_chave_api"}
      if etag:
          headers["If-None-Match"] = etag

      res = requests.get(
          "https://app.alana.shopping/api/v1/feeds/google",
          headers=headers,
      )

      if res.status_code == 304:
          return None

      etag = res.headers.get("ETag")
      return res.text
  ```
</CodeGroup>

## Headers de Resposta

| Header                 | Descrição                                      |
| ---------------------- | ---------------------------------------------- |
| `ETag`                 | Hash do conteúdo para requisições condicionais |
| `Last-Modified`        | Timestamp da última geração do feed            |
| `X-Feed-Product-Count` | Número de produtos no feed                     |
| `Cache-Control`        | `max-age=900` (cache de 15 minutos)            |

## Parâmetros de Query

| Parâmetro    | Tipo    | Descrição                                      |
| ------------ | ------- | ---------------------------------------------- |
| `catalog_id` | string  | Filtrar para um catálogo específico (opcional) |
| `limit`      | integer | Máximo de produtos por página                  |
| `offset`     | integer | Offset de paginação                            |
