### Sandbox Environment - Adding Credits Source: https://superfrete.readme.io/reference/primeiros-passos Instructions on how to add credits to your Sandbox wallet to simulate transactions and label generation. ```APIDOC ## Sandbox Environment - Adding Credits ### Description To simulate label generation and purchase scenarios in the Sandbox environment, you need to add credits to your test wallet. This process involves using a simulated PIX payment. ### Method This is a manual process within the Sandbox interface. ### Endpoint ### Steps 1. Access the Sandbox environment: 2. Click on **Recarregue com Pix** (Reload with Pix). 3. Select a recharge amount. 4. Click on **Recarregar com Pix** (Reload with Pix). 5. Click on **Copiar código PIX** (Copy PIX code). 6. Paste the copied PIX code into your browser's address bar and press Enter. This simulates the payment, and the credit will be added to your Sandbox wallet. ### Video Tutorial A step-by-step video tutorial is available at: ``` -------------------------------- ### Authentication Source: https://superfrete.readme.io/index Instructions on how to authenticate API requests using a Bearer token and the required User-Agent header. ```APIDOC ## Authentication You need a specific authentication token for the environment you are using (Sandbox or Production). ### Sandbox Environment - **URL:** `https://sandbox.superfrete.com/` - **Token Generation:** 1. Access: `https://sandbox.superfrete.com/#/integrations` 2. Click 'Integrar em Desenvolvedores'. 3. Click 'Confirmar'. 4. Copy the generated token. ### Production Environment - **URL:** `https://api.superfrete.com/` - **Token Generation:** 1. Access: `https://web.superfrete.com/#/integrations` 2. Click 'Integrar em Desenvolvedores'. 3. Click 'Confirmar'. 4. Copy the generated token. ### Token Usage Include the generated token in the `Authorization` header using the Bearer scheme. **Required Headers:** - `Authorization`: `Bearer {token}` - `User-Agent`: `Nome da sua aplicação e versão (seu_email@para_contato.com)` - `accept`: `application/json` - `content-type`: `application/json` ### Request Example (cURL) ```bash curl --request POST \ --url https://sandbox.superfrete.com/api/v0/calculator \ --header 'Authorization: Bearer {token}' \ --header 'User-Agent: Superfrete (integracao@superfrete.com)' \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` ``` -------------------------------- ### Add Balance in Sandbox Source: https://superfrete.readme.io/index Steps to add balance to your test wallet in the Sandbox environment to simulate purchase and label generation scenarios. ```APIDOC ## Add Balance in Sandbox To simulate purchase and label generation scenarios in the Sandbox environment, you need to add balance to your test wallet. **Steps:** 1. Access the Sandbox environment: `https://sandbox.superfrete.com/#/account/credits` 2. Click **Recarregue com Pix**. 3. Select a recharge amount. 4. Click **Recarregar com Pix**. 5. Click **Copiar código PIX**. 6. Paste the copied PIX code into your browser's address bar and press Enter to simulate payment. The credit will be added to your Sandbox wallet. **Video Tutorial:** https://drive.google.com/file/d/1xVSLd6vp39bCBYkQe0kbAbLl5ij72Fbu/view?usp=sharing ``` -------------------------------- ### Error Codes Source: https://superfrete.readme.io/index A list of possible error codes that may be returned by the API. ```APIDOC ## Errors Possible error codes you may receive: - `cancelled` - `unknown` - `invalid-argument` - `deadline-exceeded` - `not-found` - `already-exists` - `permission-denied` - `resource-exhausted` - `failed-precondition` - `aborted` - `out-of-range` - `unimplemented` - `internal` - `unavailable` - `data-loss` - `unauthenticated` ``` -------------------------------- ### cURL Request with Bearer Token Authentication Source: https://superfrete.readme.io/index This example demonstrates how to make a POST request to the SuperFrete API calculator endpoint using cURL. It includes the necessary Authorization header with a Bearer token and the User-Agent header for application identification. ```shell curl --request POST \ --url https://sandbox.superfrete.com/api/v0/calculator \ --header 'Authorization: Bearer {token}' \ --header 'User-Agent: Superfrete (integracao@superfrete.com)' \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Send Shipping Request (Python) Source: https://superfrete.readme.io/reference/etiquetas This Python example shows how to send a POST request to the Superfrete API to create a shipping cart using the 'requests' library. It includes the required headers and a JSON payload. ```python import requests import json url = 'https://sandbox.superfrete.com/api/v0/cart' headers = { 'User-Agent': 'Nome e versão da aplicação (email para contato técnico)', 'accept': 'application/json', 'content-type': 'application/json' } data = { 'platform': 'Documentação' } try: response = requests.post(url, headers=headers, data=json.dumps(data)) response.raise_for_status() # Raise an exception for bad status codes print('Response:', response.json()) except requests.exceptions.RequestException as e: print(f'Error sending request: {e}') ``` -------------------------------- ### Send Shipping Request (PHP) Source: https://superfrete.readme.io/reference/etiquetas This PHP example demonstrates how to send a POST request to the Superfrete API for creating a shipping cart using cURL. It configures the request with necessary headers and a JSON payload. ```php 'Documentação' ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { echo 'Response:' . $response; } curl_close($ch); ?> ``` -------------------------------- ### Send Shipping Request (Ruby) Source: https://superfrete.readme.io/reference/etiquetas This Ruby example illustrates how to send a POST request to the Superfrete API to create a shipping cart. It uses the built-in 'net/http' library and sets the required headers and JSON payload. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse('https://sandbox.superfrete.com/api/v0/cart') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request['User-Agent'] = 'Nome e versão da aplicação (email para contato técnico)' request['Accept'] = 'application/json' request['Content-Type'] = 'application/json' request.body = JSON.dump({ 'platform' => 'Documentação' }) response = http.request(request) puts "Response: #{response.body}" ``` -------------------------------- ### Shipping Request Example (JSON) Source: https://superfrete.readme.io/reference/adicionar-frete-carrinho This JSON object demonstrates a typical request payload for calculating shipping costs. It includes sender and recipient addresses, product details, package dimensions, and optional service configurations. Ensure all required fields are populated for accurate calculations. ```json { "from": { "name": "Nome do remetente", "address": "Rua do remetente", "district": "Bairro", "state_abbr": "RJ", "postal_code": "20020050", "city": "Cidade" }, "to": { "name": "Nome do destinatário", "address": "Rua do destinatário", "district": "Bairro", "city": "Cidade", "state_abbr": "SP", "postal_code": "01153000", "email": "email@mail.com" }, "service": 1, "products": [ { "name": "Produto 1", "quantity": 1, "unitary_value": 100 }, { "name": "Produto 2", "quantity": 2, "unitary_value": 200 } ], "volumes": { "height": 2, "width": 11, "length": 16, "weight": 0.3 }, "options": { "invoice": { "key": "123456" } }, "platform": "Insira aqui o nome da sua plataforma" } ``` -------------------------------- ### Send Shipping Request (Node.js) Source: https://superfrete.readme.io/reference/etiquetas This Node.js example shows how to make a POST request to the Superfrete API for creating a shipping cart. It utilizes the 'axios' library for HTTP requests and includes the necessary headers and JSON body. ```javascript const axios = require('axios'); const sendShippingRequest = async () => { const url = 'https://sandbox.superfrete.com/api/v0/cart'; const headers = { 'User-Agent': 'Nome e versão da aplicação (email para contato técnico)', 'accept': 'application/json', 'content-type': 'application/json' }; const data = { 'platform': 'Documentação' }; try { const response = await axios.post(url, data, { headers }); console.log('Response:', response.data); } catch (error) { console.error('Error sending request:', error); } }; sendShippingRequest(); ``` -------------------------------- ### GET /api/v0/user Source: https://superfrete.readme.io/reference/user-buscar-informa%C3%A7%C3%B5es-do-usu%C3%A1rio Retrieves user information based on the provided token. This includes details such as name, contact information, document, shipping limits, and account balance. ```APIDOC ## GET /api/v0/user ### Description Retrieves user information based on the provided token. This includes details such as name, contact information, document, shipping limits, and account balance. ### Method GET ### Endpoint https://sandbox.superfrete.com/api/v0/user ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "No request body needed for this GET request." } ``` ### Response #### Success Response (200) - **id** (string) - User's unique identifier. - **firstname** (string) - User's first name. - **lastname** (string) - User's last name. - **phone** (string) - User's phone number. - **email** (string) - User's email address. - **document** (string) - User's document number (CPF). - **limits** (object) - User's shipping limits. - **shipments** (integer) - Total number of shipments the user has pending. - **shipments_available** (integer) - Remaining shipping labels available for the user. - **balance** (number) - Total balance in the user's account. #### Response Example ```json { "id": "3kCKGqzlPFfCEj2X1Tkob07SN2M2", "firstname": "Nome", "lastname": "Sobrenome", "phone": "+5511999999999", "email": "mail@gmail.com", "document": "00000000000", "limits": { "shipments": 3, "shipments_available": 2 }, "balance": 1763.04 } ``` #### Error Response (400) - **Description**: Indicates a bad request. #### Error Response Example ```json { "example": "Empty JSON object for error response." } ``` ``` -------------------------------- ### GET /websites/superfrete_readme_io Source: https://superfrete.readme.io/reference/tag-informa%C3%A7%C3%B5es-do-pedido Retrieves detailed information about a specific shipping label using its unique ID. The API returns a JSON object containing all details associated with that label. ```APIDOC ## GET /websites/superfrete_readme_io ### Description Retrieves detailed information about a specific shipping label using its unique ID. The API returns a JSON object containing all details associated with that label. ### Method GET ### Endpoint /websites/superfrete_readme_io ### Parameters #### Path Parameters - **id** (String) - Required - The unique ID of the shipping label. ### Request Example ```json { "example": "No request body needed for GET request" } ``` ### Response #### Success Response (200) - **id** (String) - The unique ID of the shipping label generated by SuperFrete. - **protocol** (String) - An internal protocol identifier of SuperFrete, usually identical to the id. - **format** (String) - The packaging format used (e.g., "box"). - **delivery** (Integer) - The estimated delivery time in business days. - **delivery_min** (Integer) - The minimum estimated delivery time in business days. - **delivery_max** (Integer) - The maximum estimated delivery time in business days. - **discount** (Float) - The discount amount applied to the shipping, if any. - **height** (String) - The height of the package in centimeters. - **width** (String) - The width of the package in centimeters. - **length** (String) - The length of the package in centimeters. - **weight** (String) - The weight of the package in kilograms. - **from** (Object) - Sender details. - **address** (String) - Sender's address. - **city** (String) - Sender's city. - **complement** (String) - Sender's address complement. - **email** (String) - Sender's email. - **district** (String) - Sender's neighborhood. - **document** (String) - Sender's document (CPF/CNPJ). - **name** (String) - Sender's full name. - **location_number** (String) - Sender's address number. - **postal_code** (String) - Sender's postal code. - **state_abbr** (String) - Sender's state abbreviation (UF). - **country_id** (String) - Sender's country code (always "BR" for Brazil). - **to** (Object) - Recipient details. - **address** (String) - Recipient's address. - **city** (String) - Recipient's city. - **complement** (String) - Recipient's address complement. - **district** (String) - Recipient's neighborhood. - **document** (String) - Recipient's document (CPF/CNPJ). - **name** (String) - Recipient's full name. - **location_number** (String) - Recipient's address number. - **postal_code** (String) - Recipient's postal code. - **state_abbr** (String) - Recipient's state abbreviation (UF). - **country_id** (String) - Recipient's country code (always "BR" for Brazil). - **invoice** (Object or null) - Invoice details, if used. Will be null if a content declaration is used. - **own_hand** (Boolean) - Indicates if the Own Hand service was requested. - **receipt** (Boolean) - Indicates if the Receipt of Delivery service was requested. - **price** (Float) - The total shipping cost. - **tracking** (String or null) - The tracking code for the package. - **status** (String) - The current status of the label (e.g., "delivered"). - **service_id** (Integer) - The shipping service code used (1 for PAC, 2 for SEDEX, 17 for Mini Envios). - **products** (Array of Objects) - List of products declared for the package. - **name** (String) - Product name. - **quantity** (String) - Product quantity. - **unitary_value** (String) - Product unit value. - **insurance_value** (Float or null) - The declared insurance value of the package, if applicable. - **generated_at** (String) - Timestamp (ISO 8601 UTC) when the label was generated. - **posted_at** (String or null) - Timestamp (ISO 8601 UTC) when the package was posted. - **created_at** (String) - Timestamp (ISO 8601 UTC) when the label order was created. - **updated_at** (String) - Timestamp (ISO 8601 UTC) when the label information was last updated. - **print** (Object) - Information for printing the label. - **url** (String) - URL to access the PDF file of the label for printing. - **tags** (Array of Objects) - List of tags associated with the label. - **tag** (String) - The tag value. - **url** (String) - The URL associated with the tag on the origin platform. #### Response Example ```json { "id": "12345abcde", "protocol": "12345abcde", "format": "box", "delivery": 5, "delivery_min": 4, "delivery_max": 6, "discount": 7.43, "height": "15", "width": "25", "length": "26", "weight": "2.20", "from": { "address": "Rua Exemplo, 123", "city": "São Paulo", "complement": "Apto 4B", "email": "remetente@email.com", "district": "Centro", "document": "12345678900", "name": "Nome Remetente", "location_number": "123", "postal_code": "01000000", "state_abbr": "SP", "country_id": "BR" }, "to": { "address": "Avenida Teste, 456", "city": "Rio de Janeiro", "complement": null, "district": "Copacabana", "document": "98765432100", "name": "Nome Destinatario", "location_number": "456", "postal_code": "20000000", "state_abbr": "RJ", "country_id": "BR" }, "invoice": null, "own_hand": false, "receipt": true, "price": 27.37, "tracking": "AA923452383BR", "status": "delivered", "service_id": 1, "products": [ { "name": "Produto Exemplo", "quantity": "2", "unitary_value": "50.00" } ], "insurance_value": 100.00, "generated_at": "2023-10-27T10:00:00Z", "posted_at": "2023-10-27T12:00:00Z", "created_at": "2023-10-27T09:00:00Z", "updated_at": "2023-10-27T15:00:00Z", "print": { "url": "https://api.superfrete.com/v1/labels/12345abcde/print" }, "tags": [ { "tag": "3101481", "url": "http://origin.platform.com/order/3101481" } ] } ``` ``` -------------------------------- ### Webhook Authentication Header Example Source: https://superfrete.readme.io/reference/webhook Demonstrates how to include the JWT token in the Authorization header for API requests. The token is obtained from the SuperFrete dashboard and is essential for authenticating all webhook-related operations. ```http Authorization: Bearer {token} ``` -------------------------------- ### List Addresses - Node.js Request Source: https://superfrete.readme.io/reference/usu%C3%A1rio Example of how to list user addresses using Node.js. This snippet utilizes the 'node-fetch' library to make the HTTP GET request to the Superfrete API. ```javascript const fetch = require('node-fetch'); const options = { method: 'GET', headers: { 'User-Agent': 'Nome e versão da aplicação (email para contato técnico)', 'Accept': 'application/json' } }; fetch('https://sandbox.superfrete.com/api/v0/user/addresses', options) .then(response => response.json()) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### List Addresses - PHP Request Source: https://superfrete.readme.io/reference/usu%C3%A1rio A PHP example for retrieving user addresses via the Superfrete API. This snippet uses cURL to send the GET request and includes necessary headers. ```php ``` -------------------------------- ### GET /api/v0/order/info/{id} Source: https://superfrete.readme.io/reference/tag-informa%C3%A7%C3%B5es-do-pedido Retrieves detailed information about a specific order using its unique ID. ```APIDOC ## GET /api/v0/order/info/{id} ### Description Retrieves detailed information about a specific order using its unique ID. ### Method GET ### Endpoint https://sandbox.superfrete.com/api/v0/order/info/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Id do pedido SuperFrete ### Request Example ```json { "example": "No request body needed for GET request." } ``` ### Response #### Success Response (200) - **id** (string) - Order ID - **format** (string) - Package format - **delivery** (integer) - Estimated delivery time - **delivery_min** (integer) - Minimum estimated delivery time - **delivery_max** (integer) - Maximum estimated delivery time - **discount** (number) - Discount applied to the order - **height** (integer) - Package height - **width** (integer) - Package width - **length** (integer) - Package length - **weight** (number) - Package weight - **from** (object) - Sender information - **address** (string) - **city** (string) - **complement** (any) - **district** (string) - **document** (any) - **name** (string) - **location_number** (string) - **postal_code** (string) - **state_abbr** (string) - **country_id** (string) - **to** (object) - Recipient information - **address** (string) - **city** (string) - **complement** (any) - **district** (string) - **document** (any) - **name** (string) - **location_number** (string) - **postal_code** (string) - **state_abbr** (string) - **country_id** (string) - **invoice** (string) - Invoice number - **own_hand** (boolean) - Whether the package is for own hand delivery - **receipt** (boolean) - Whether a receipt is required - **price** (number) - Order price - **tracking** (string) - Tracking number - **status** (string) - Order status - **service_id** (integer) - Service ID - **products** (array) - List of products in the order - **name** (string) - **quantity** (string) - **unitary_value** (string) - **insurance_value** (any) - Insurance value - **generated_at** (string) - Timestamp when the order was generated - **posted_at** (string) - Timestamp when the order was posted - **created_at** (string) - Timestamp when the order was created - **updated_at** (string) - Timestamp when the order was updated #### Response Example ```json { "id": "JlmCKlsK7G471C4ChJYX", "format": "box", "delivery": 5, "delivery_min": 5, "delivery_max": 5, "discount": 5.01, "height": 2, "width": 11, "length": 16, "weight": 0.3, "from": { "address": "Rua do remetente", "city": "Cidade", "complement": null, "district": "Bairro", "document": null, "name": "Nome do remetente", "location_number": "S/N", "postal_code": "20020050", "state_abbr": "RJ", "country_id": "BR" }, "to": { "address": "Rua do destinatário", "city": "Cidade", "complement": null, "district": "Bairro", "document": null, "name": "Nome do destinatário", "location_number": "S/N", "postal_code": "01153000", "state_abbr": "SP", "country_id": "BR" }, "invoice": "123456", "own_hand": false, "receipt": false, "price": 19.79, "tracking": "EC451638075BR", "status": "pending", "service_id": 1, "products": [ { "name": "Produto 1", "quantity": "1", "unitary_value": "100" }, { "name": "Produto 2", "quantity": "2", "unitary_value": "200" } ], "insurance_value": null, "generated_at": "2022-12-03T17:36:01.159Z", "posted_at": "2022-12-03T17:36:01.159Z", "created_at": "2022-12-03T17:34:39.399Z", "updated_at": "2022-12-03T17:36:04.481Z" } ``` ``` -------------------------------- ### Finalizar Pedido e Gerar Etiqueta Source: https://superfrete.readme.io/reference/apiintegrationv1checkout Este endpoint permite realizar o pagamento de uma etiqueta de frete previamente gerada, utilizando o saldo disponível na sua conta SuperFrete. É necessário ter saldo suficiente na carteira para prosseguir. ```APIDOC ## POST /api/v1/orders/finalize ### Description Este endpoint permite realizar o pagamento de uma etiqueta de frete previamente gerada, utilizando o saldo disponível na sua conta SuperFrete. O status da etiqueta será atualizado para 'released' após o pagamento bem-sucedido. ### Method POST ### Endpoint /api/v1/orders/finalize ### Parameters #### Request Body - **id** (string) - Required - O ID da etiqueta de frete gerada previamente pela API de Envio de Frete. ### Request Example ```json { "id": "" } ``` ### Response #### Success Response (200) - **message** (string) - Mensagem de sucesso indicando que o pagamento foi processado e a etiqueta está pronta para postagem. #### Response Example ```json { "message": "Pagamento processado com sucesso. Etiqueta liberada para postagem." } ``` #### Error Response (400) - **error** (string) - Mensagem de erro indicando a causa da falha (ex: saldo insuficiente, ID inválido). #### Error Response Example ```json { "error": "Saldo insuficiente na carteira." } ``` ``` -------------------------------- ### POST /api/v0/webhook Source: https://superfrete.readme.io/reference/criar-webhook-app Creates a new Webhook App for the authenticated user. This endpoint allows you to register a URL to receive real-time notifications about order events. ```APIDOC ## POST /api/v0/webhook ### Description Creates a new Webhook App for the authenticated user. This endpoint allows you to register a URL to receive real-time notifications about order events. ### Method POST ### Endpoint `/api/v0/webhook` ### Parameters #### Query Parameters - **event** (string) - Required - The event to subscribe to. Available events: `order.created`, `order.released`, `order.generated`, `order.posted`, `order.delivered`, `order.cancelled`. #### Request Body - **url** (string) - Required - The URL where the webhook events will be sent. ### Request Example ```json { "url": "https://your-callback-url.com/webhook" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created webhook. - **url** (string) - The registered webhook URL. - **event** (string) - The subscribed event. #### Response Example ```json { "id": "whk_abc123xyz789", "url": "https://your-callback-url.com/webhook", "event": "order.created" } ``` ``` -------------------------------- ### Exemplo de Requisição de Cotação de Frete com Produtos Source: https://superfrete.readme.io/reference/calculator Este exemplo demonstra como realizar uma cotação de frete enviando as dimensões dos produtos individuais. A API calculará as dimensões ideais da caixa para o envio. ```json { "from":{ "postal_code":"01153000" }, "to":{ "postal_code":"20020050" }, "services":"1,2,17", "options":{ "own_hand":false, "receipt":false, "insurance_value":0, "use_insurance_value":false }, "products":[ { "quantity":1, "height":4, "length":3, "width":3, "weight": 0.03 } ] } ``` -------------------------------- ### List Addresses - Python Request Source: https://superfrete.readme.io/reference/usu%C3%A1rio This Python code demonstrates how to list user addresses using the 'requests' library. It sends a GET request to the Superfrete API with the required headers. ```python import requests url = 'https://sandbox.superfrete.com/api/v0/user/addresses' headers = { 'User-Agent': 'Nome e versão da aplicação (email para contato técnico)', 'Accept': 'application/json' } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### POST /api/v0/webhook Source: https://superfrete.readme.io/reference/criar-webhook-app Creates a new webhook application to receive real-time notifications for specific events. You can specify the name, URL, and the events you want to subscribe to. ```APIDOC ## POST /api/v0/webhook ### Description Creates a new webhook application to receive real-time notifications for specific events. You can specify the name, URL, and the events you want to subscribe to. ### Method POST ### Endpoint https://sandbox.superfrete.com/api/v0/webhook ### Parameters #### Request Body - **name** (string) - Required - Nome do Webhook app - **url** (string) - Required - URL que receberá as notificações - **events** (array of strings) - Optional - Lista de eventos para receber as atualizações ### Request Example ```json { "name": "Meu Webhook App", "url": "https://meusite.com/webhook", "events": ["order.posted", "order.delivered"] } ``` ### Response #### Success Response (201) - **id** (string) - Unique identifier for the webhook app. - **name** (string) - The name of the webhook app. - **url** (string) - The URL that will receive notifications. - **secret_token** (string) - A token for securing webhook communications. - **events** (array of strings) - The list of events the webhook is subscribed to. - **is_active** (boolean) - Indicates if the webhook is currently active. - **created_at** (string) - The timestamp when the webhook was created. #### Response Example ```json { "id": "webhook-app-123", "name": "Meu Webhook App", "url": "https://meusite.com/webhook", "secret_token": "abc123def456", "events": ["order.posted", "order.delivered"], "is_active": true, "created_at": "2023-10-01T12:00:00Z" } ``` #### Error Response (400) - An empty JSON object is returned for bad requests. ```