Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

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)

asyncfunctionobterToken(){constres=awaitfetch("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){consttxt=awaitres.text();thrownewError(`Falha ao obter token (${res.status}): ${txt}`);}constdata=awaitres.json();returndata.token;// string}

✅ Exemplo Delphi (Indy)

uses IdHTTP, System.SysUtils;
functionObterToken: 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)

asyncfunctionobterInfoProduto(gtin,token){consturl=`https://gtin.rscsistemas.com.br/api/gtin/infor/${encodeURIComponent(gtin)}`;constres=awaitfetch(url,{headers: {"Authorization": `Bearer ${token}`,"Accept": "application/json"}});if(res.status===404){consterr=awaitres.json();thrownewError(err.mensagem||"Produto não encontrado");}if(!res.ok){consttxt=awaitres.text();thrownewError(`Erro ${res.status}: ${txt}`);}returnres.json();}

✅ Exemplo Delphi (Indy)

functionObterInfoProduto(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)

asyncfunctionbaixarImagem(gtin,token){consturl=`https://gtin.rscsistemas.com.br/api/gtin/img/${encodeURIComponent(gtin)}`;constres=awaitfetch(url,{headers: {"Authorization": `Bearer ${token}`}});if(res.status===404){consterr=awaitres.json();thrownewError(err.mensagem||"Produto não encontrado na base de dados");}if(res.status===204){thrownewError("Produto encontrado, porem sem imagem cadastrada");}if(!res.ok){consttxt=awaitres.text();thrownewError(`Erro ${res.status}: ${txt}`);}constblob=awaitres.blob();consturlBlob=URL.createObjectURL(blob);consta=document.createElement("a");a.href=urlBlob;a.download=`${gtin}.png`;a.click();URL.revokeObjectURL(urlBlob);}

✅ Exemplo Delphi (Indy)

procedureBaixarImagem(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

Stars

34 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages