Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

OpenSourceCommunityBrasil/Client-API-GTIN

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📃 Client API GTIN

OSCBR - Open Source Community Brasil

🌐 Site: https://gtin.rscsistemas.com.br


📋 Cadastro e Autenticação

Para utilizar a API GTIN, é necessário possuir um usuário e senha.
Se ainda não tiver, cadastre-se em:
🔗 https://gtin.rscsistemas.com.br/cadastro


🔐 Autenticação e Token

Endpoint

  • URL: https://gtin.rscsistemas.com.br/oauth/token
  • Método: POST
  • Headers obrigatórios:
    • Authorization: Basic <base64_encoded_credentials> (onde as credenciais username:password são codificadas em base64)
    • Accept: application/json

Observações

  • O token expira em 1 hora.
  • Rate limit: 20 req/min (plano Free).

✅ Exemplo cURL

curl -X POST "https://gtin.rscsistemas.com.br/oauth/token" \
  -H "Authorization: Basic <base64_encoded_credentials>" \
  -H "Accept: application/json"

✅ Exemplo JavaScript (fetch)

async function obterToken() {
  const res = await fetch("https://gtin.rscsistemas.com.br/oauth/token", {
    method: "POST",
    headers: {
      "Authorization": "Basic <base64_encoded_credentials>", // Substitua pelo valor codificado em base64
      "Accept": "application/json"
    }
  });

  if (!res.ok) {
    const txt = await res.text();
    throw new Error(`Falha ao obter token (${res.status}): ${txt}`);
  }
  const data = await res.json();
  return data.token; // string
}

✅ Exemplo Delphi (Indy)

uses IdHTTP, System.SysUtils;

function ObterToken: string;
var
  HTTP: TIdHTTP;
  Resp: string;
begin
  HTTP := TIdHTTP.Create(nil);
  try
    HTTP.Request.CustomHeaders.Values['Authorization'] := 'Basic <base64_encoded_credentials>'; // Substitua pelo valor codificado em base64
    HTTP.Request.Accept := 'application/json';

    Resp := HTTP.Post('https://gtin.rscsistemas.com.br/oauth/token', nil);
    Result := Resp;
  finally
    HTTP.Free;
  end;
end;

Respostas

  • 200 OK
{ "token": "eyJhbGciOiAiQUVTMjU2IiwgInR5cCI6ICJKV1QifQ==..." }
  • 401 Unauthorized
{ "erro": "Não autenticado. Verifique suas credenciais." }

📦 Informações do Produto

Endpoint

  • URL: https://gtin.rscsistemas.com.br/api/gtin/infor/:gtin
  • Método: GET
  • Path param: :gtin (string)
  • Header: Authorization: Bearer <SEU_TOKEN>

✅ Exemplo cURL

GTIN="7896116900029"
TOKEN="SEU_TOKEN_AQUI"

curl -X GET "https://gtin.rscsistemas.com.br/api/gtin/infor/$GTIN" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json"

✅ Exemplo JavaScript (fetch)

async function obterInfoProduto(gtin, token) {
  const url = `https://gtin.rscsistemas.com.br/api/gtin/infor/${encodeURIComponent(gtin)}`;
  const res = await fetch(url, {
    headers: {
      "Authorization": `Bearer ${token}`,
      "Accept": "application/json"
    }
  });

  if (res.status === 404) {
    const err = await res.json();
    throw new Error(err.mensagem || "Produto não encontrado");
  }
  if (!res.ok) {
    const txt = await res.text();
    throw new Error(`Erro ${res.status}: ${txt}`);
  }
  return res.json();
}

✅ Exemplo Delphi (Indy)

function ObterInfoProduto(const GTIN, Token: string): string;
var
  HTTP: TIdHTTP;
  URL: string;
begin
  HTTP := TIdHTTP.Create(nil);
  try
    HTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + Token;
    HTTP.Request.Accept := 'application/json';

    URL := Format('https://gtin.rscsistemas.com.br/api/gtin/infor/%s', [GTIN]);
    Result := HTTP.Get(URL);
  finally
    HTTP.Free;
  end;
end;

Respostas

  • 200 OK
{
  "ean": "7896116900029",
  "ean_tipo": "EAN13",
  "ncm": 7133399,
  "nome": "FEIJAO CARIOCA KICALDO T1 1KG",
  "marca": "KICALDO",
  "pais": "BRASIL",
  "categoria": "Carioca",
  "link_foto": "https://gtin.rscsistemas.com.br/api/gtin/img/7896116900029"
}
  • 404 Not Found
{ "mensagem": "Produto não encontrado na base de dados" }

🖼️ Imagem do Produto

Endpoint

  • URL: https://gtin.rscsistemas.com.br/api/gtin/img/:gtin
  • Método: GET
  • Path param: :gtin (string)
  • Header: Authorization: Bearer <SEU_TOKEN>

✅ Exemplo cURL (salvar arquivo)

GTIN="7896116900029"
TOKEN="SEU_TOKEN_AQUI"

curl -L "https://gtin.rscsistemas.com.br/api/gtin/img/$GTIN" \
  -H "Authorization: Bearer $TOKEN" \
  --output "${GTIN}.png"

✅ Exemplo JavaScript (fetch)

async function baixarImagem(gtin, token) {
  const url = `https://gtin.rscsistemas.com.br/api/gtin/img/${encodeURIComponent(gtin)}`;
  const res = await fetch(url, {
    headers: { "Authorization": `Bearer ${token}` }
  });

  if (res.status === 404) {
    const err = await res.json();
    throw new Error(err.mensagem || "Produto não encontrado na base de dados");
  }
  if (res.status === 204) {
    throw new Error("Produto encontrado, porem sem imagem cadastrada");
  }
  if (!res.ok) {
    const txt = await res.text();
    throw new Error(`Erro ${res.status}: ${txt}`);
  }

  const blob = await res.blob();
  const urlBlob = URL.createObjectURL(blob);
  const a = document.createElement("a");
  a.href = urlBlob;
  a.download = `${gtin}.png`;
  a.click();
  URL.revokeObjectURL(urlBlob);
}

✅ Exemplo Delphi (Indy)

procedure BaixarImagem(const GTIN, Token, CaminhoDestino: string);
var
  HTTP: TIdHTTP;
  FileStream: TFileStream;
  URL: string;
begin
  HTTP := TIdHTTP.Create(nil);
  try
    HTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + Token;
    URL := Format('https://gtin.rscsistemas.com.br/api/gtin/img/%s', [GTIN]);
    FileStream := TFileStream.Create(CaminhoDestino + GTIN + '.png', fmCreate);
    try
      HTTP.Get(URL, FileStream);
    finally
      FileStream.Free;
    end;
  finally
    HTTP.Free;
  end;
end;

Respostas

  • 200 OKimage/png

Exemplo de imagem retornada:
Exemplo de imagem

  • 404 Not Found
{ "mensagem": "Produto não encontrado na base de dados" }
  • 204 No Content

Imagem exemplo para 204:
Produto sem imagem


🧠 Boas Práticas

  • Sempre envie o header Authorization: Bearer <token> nos endpoints protegidos.
  • Trate a expiração do token solicitando um novo via /oauth/token.
  • Valide o GTIN localmente antes de consultar.
  • Utilize Accept: application/json para respostas estruturadas.

Desenvolvido por RSC Sistemas
🌐 https://rscsistemas.com.br

Roniery Santos Cardoso
📧 E-mail: roniery@rscsistemas.com.br
📱 WhatsApp: +55 92 4141-2737

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.