### Retrieve Products from Catalog (Node.js) Source: https://developers.vnda.com.br/reference/produto Example of fetching products from the VNDA catalog using Node.js with the 'axios' library. This code sends a GET request to the API and handles the JSON response. Ensure 'axios' is installed (`npm install axios`). ```javascript const axios = require('axios'); const getProducts = async () => { try { const response = await axios.get('https://api.vnda.com.br/api/v2/products', { headers: { 'accept': 'application/json' } }); console.log(response.data); return response.data; } catch (error) { console.error('Error fetching products:', error); } }; getProducts(); ``` -------------------------------- ### Retrieve Products from Catalog (Ruby) Source: https://developers.vnda.com.br/reference/produto Ruby example using the 'httparty' gem to fetch products from the VNDA API. This code sends a GET request and prints the JSON response. Ensure 'httparty' is installed (`gem install httparty`). ```ruby require 'httparty' url = 'https://api.vnda.com.br/api/v2/products' begin response = HTTParty.get(url, headers: { 'accept' => 'application/json' }) if response.success? puts response.parsed_response else puts "Error: #{response.code} - #{response.message}" end rescue HTTParty::Error => e puts "HTTParty Error: #{e.message}" rescue StandardError => e puts "An error occurred: #{e.message}" end ``` -------------------------------- ### Create Discount using Python Source: https://developers.vnda.com.br/reference/promo%C3%A7%C3%B5es This Python example shows how to create a discount using the VNDA API with the 'requests' library. It sends a POST request with JSON data and appropriate headers. Ensure you have the 'requests' library installed (`pip install requests`). ```python import requests import json url = 'https://api.vnda.com.br/api/v2/discounts' payload = { 'name': 'Back to School Discount', 'start_at': '2024-09-01T08:00:00Z', 'end_at': '2024-09-15T17:00:00Z', 'enabled': True, 'description': '10% off selected school supplies.' } headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } try: response = requests.post(url, headers=headers, data=json.dumps(payload)) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) print('Discount created successfully:') print(response.json()) except requests.exceptions.RequestException as e: print(f'Error creating discount: {e}') if hasattr(e, 'response') and e.response is not None: print('Response body:', e.response.text) ``` -------------------------------- ### Create Discount using Node.js Source: https://developers.vnda.com.br/reference/promo%C3%A7%C3%B5es This Node.js example shows how to create a discount via the VNDA API using the 'axios' library. It sends a POST request with the necessary headers and a JSON body containing discount details. Ensure you have 'axios' installed (`npm install axios`). ```javascript const axios = require('axios'); const createDiscount = async (data) => { try { const response = await axios.post('https://api.vnda.com.br/api/v2/discounts', data, { headers: { 'accept': 'application/json', 'content-type': 'application/json' } }); return response.data; } catch (error) { console.error('Error creating discount:', error.response.data); throw error; } }; // Example usage: // createDiscount({ // "name": "Summer Sale", // "start_at": "2024-07-01T10:00:00Z", // "end_at": "2024-07-31T23:59:59Z", // "enabled": true, // "description": "Get 20% off all summer items." // }).then(discount => console.log('Discount created:', discount)); ``` -------------------------------- ### GET /products/{id} Source: https://developers.vnda.com.br/reference/get-api-v2-products-product_id-price Retrieves detailed information for a specific product by its ID. This includes pricing, availability, discount rules, installment options, and variant details. ```APIDOC ## GET /products/{id} ### Description Retrieves detailed information for a specific product by its ID. This includes pricing, availability, discount rules, installment options, and variant details. ### Method GET ### Endpoint `/products/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the product. #### Query Parameters None #### Request Body None ### Request Example ```bash GET /products/12345 ``` ### Response #### Success Response (200) - **available** (boolean) - Indicates if the product is currently available. - **on_sale** (boolean) - Indicates if the product is on sale. - **price** (number) - The current price of the product. - **sale_price** (number) - The promotional sale price of the product. - **intl_price** (number) - The international price of the product. - **cashback** (object) - Cashback details. - **amount** (number) - The cashback amount. - **percentage** (number) - The cashback percentage. - **discount_rule** (object) - Details about any applicable discount rules. - **installments** (array) - An array of available installment plans. - **number** (integer) - The installment number. - **price** (number) - The price for this installment. - **interest** (boolean) - Indicates if interest is applied to this installment. - **interest_rate** (number) - The interest rate for this installment. - **total** (number) - The total price for this installment. - **updated_at** (string) - The date and time of the last update. - **variants** (array) - An array of product variants. - **main** (boolean) - Defines if the variant is the main one. - **sku** (string) - The SKU code of the variant. - **price** (number) - The price of the variant. - **on_sale** (boolean) - Indicates if the variant is on sale. - **sale_price** (number) - The sale price of the variant. - **intl_price** (number) - The international price of the variant. - **available** (boolean) - Indicates if the variant is available. - **properties** (object) - Attributes of the variant. #### Response Example ```json { "available": true, "on_sale": false, "price": 100.00, "sale_price": null, "intl_price": 120.00, "cashback": { "amount": 5.00, "percentage": 5 }, "discount_rule": {}, "installments": [ { "number": 1, "price": 10.30, "interest": true, "interest_rate": 1.5, "total": 10.30 } ], "updated_at": "2023-10-27T10:00:00Z", "variants": [ { "main": true, "sku": "SKU123", "price": 100.00, "on_sale": false, "sale_price": null, "intl_price": 120.00, "available": true, "properties": {} } ] } ``` ``` -------------------------------- ### Get Orders List (Shell) Source: https://developers.vnda.com.br/reference/pedidos Retrieves a list of orders from the VNDA API. This example uses cURL to make a GET request to the orders endpoint, specifying the number of results per page and whether to include customizations in the total. It sets the 'accept' header to 'application/json'. ```shell curl --request GET \ --url 'https://api.vnda.com.br/api/v2/orders?per_page=100&include_customizations_in_total=false' \ --header 'accept: application/json' ``` -------------------------------- ### Get Shipping Address - Node.js Example Source: https://developers.vnda.com.br/reference/envio-de-pedido Example of fetching shipping address using Node.js. This code makes an HTTP GET request to the VNDA API endpoint, expecting a JSON response. Ensure you have a library like 'axios' or 'node-fetch' installed. ```JavaScript // Placeholder for Node.js code example // const axios = require('axios'); // const orderCode = 'your_order_code'; // axios.get(`https://api.vnda.com.br/api/v2/orders/${orderCode}/shipping_address`, { // headers: { // 'accept': 'application/json' // } // }) // .then(response => { // console.log(response.data); // }) // .catch(error => { // console.error(error); // }); ``` -------------------------------- ### Product Schema Example (JSON) Source: https://developers.vnda.com.br/reference/get-api-v2-products-id An example illustrating the structure of a product object as returned by the VNDA API. This example showcases typical values for properties like category tags, descriptions, and image URLs. It's useful for understanding data representation. ```json { "title": "Product", "type": "object", "description": "Modelo que representa um produto na API", "properties": { "id": { "type": "integer", "description": "Código identificador `ID` do priduto" }, "active": { "type": "boolean", "description": "Indica se o produto está ativo (`true`) ou invativo (`false`)" }, "available": { "type": "boolean", "description": "Indica se o produto está disponível (`true`) ou indisponível (`false`)" }, "category_tags": { "type": "array", "items": { "type": "object", "properties": { "tag_type": { "type": "string", "description": "Tipo de tag" }, "name": { "type": "string", "description": "Nome da tag" }, "title": { "type": "string", "description": "Título da tag" } } }, "example": [ { "tag_type": "flag", "name": "tag-veganos", "title": "Veg" }, { "tag_type": "flag", "name": "liquida10", "title": "10OFF" } ] }, "description": { "type": "string", "description": "Descrição do produto" }, "discount_id": { "type": "integer", "description": "Código de desconto" }, "html_description": { "type": "string", "description": "Descrição do produto em HTML" }, "image_url": { "type": "string", "description": "URL da imagem do produto" }, "installments": { "type": "array", "description": "Relação das parcelas para pagamento parcelado", "items": { ``` -------------------------------- ### Create Discount using Ruby Source: https://developers.vnda.com.br/reference/promo%C3%A7%C3%B5es This Ruby example demonstrates creating a discount using the VNDA API with the 'net/http' library. It constructs a POST request with JSON data and appropriate headers. This code assumes basic familiarity with Ruby HTTP requests. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse('https://api.vnda.com.br/api/v2/discounts') request = Net::HTTP::Post.new(uri) request['Accept'] = 'application/json' request['Content-Type'] = 'application/json' # Example payload (replace with actual data) payload = { name: "Winter Clearance", start_at: "2024-12-01T09:00:00Z", end_at: "2024-12-31T17:00:00Z", enabled: true, description: "Up to 50% off selected items." }.to_json request.body = payload response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end puts "Status Code: #{response.code}" puts JSON.parse(response.body) ``` -------------------------------- ### Retrieve Products from Catalog (PHP) Source: https://developers.vnda.com.br/reference/produto PHP code example for fetching products from the VNDA API. This script uses cURL to make the GET request and outputs the JSON response. It demonstrates basic cURL setup for making API calls. ```php ``` -------------------------------- ### POST /api/v2/discounts Source: https://developers.vnda.com.br/reference/promo%C3%A7%C3%B5es Creates a new product promotion. You can specify details such as name, start and end dates, description, and enable/disable the promotion. ```APIDOC ## POST /api/v2/discounts ### Description Creates a new product promotion. You can specify details such as name, start and end dates, description, and enable/disable the promotion. ### Method POST ### Endpoint https://api.vnda.com.br/api/v2/discounts ### Parameters #### Query Parameters * **name** (string) - Required - The name of the promotion. * **start_at** (date-time) - Required - The start date and time of the promotion. * **end_at** (date-time) - Required - The end date and time of the promotion. * **valid_to** (string) - Optional - Enum: `store`, `cart`. Specifies when the discount is valid. * **description** (string) - Optional - A description for the promotion. * **enabled** (boolean) - Optional - Defaults to true. Whether the promotion is enabled. * **email** (string) - Optional - Associated email for the promotion. * **cpf** (string) - Optional - Associated CPF for the promotion. * **tags** (string) - Optional - Tags associated with the promotion. * **cumulative** (boolean) - Optional - Defaults to true. Whether the promotion can be combined with others. #### Request Body (No specific request body parameters are listed, but the query parameters above are expected to be sent in the request body) ### Request Example ```json { "name": "Summer Sale", "start_at": "2024-07-01T10:00:00Z", "end_at": "2024-07-31T23:59:59Z", "description": "Get 20% off selected summer items.", "enabled": true, "cumulative": false, "valid_to": "store" } ``` ### Response #### Success Response (201) - **id** (integer) - The unique identifier of the created promotion. - **name** (string) - The name of the promotion. - **description** (string) - The description of the promotion. - **start_at** (date-time) - The start date and time of the promotion. - **end_at** (date-time) - The end date and time of the promotion. - **enabled** (boolean) - Indicates if the promotion is enabled. - **facebook** (boolean) - Indicates if the promotion is linked to Facebook (deprecated). - **valid_to** (string) - Specifies when the discount is valid. - **email** (string) - Associated email for the promotion. - **cpf** (string) - Associated CPF for the promotion. - **tags** (string) - Tags associated with the promotion. #### Response Example (201) ```json { "id": 123, "name": "Summer Sale", "description": "Get 20% off selected summer items.", "start_at": "2024-07-01T10:00:00Z", "end_at": "2024-07-31T23:59:59Z", "enabled": true, "facebook": false, "valid_to": "store", "email": null, "cpf": null, "tags": "summer,sale" } ``` #### Error Response (422) - **errors** (object) - Contains details about validation errors. - **{field}** (array of strings) - An array of error messages for a specific field. #### Response Example (422) ```json { "errors": { "name": [ "Name is required." ], "start_at": [ "Start at must be a valid date-time." ] } } ``` ``` -------------------------------- ### List Clients Node.js Request Source: https://developers.vnda.com.br/reference/clientes-1 Example of how to fetch a list of clients using the Node.js 'axios' library. This snippet shows setting up the request and handling the response, including error management. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://api.vnda.com.br/api/v2/clients', headers: { 'accept': 'application/json' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Get Shipping Address - PHP Example Source: https://developers.vnda.com.br/reference/envio-de-pedido Example of fetching shipping address using PHP. This code uses cURL to send a GET request to the VNDA API. The response is then decoded from JSON. ```PHP ``` -------------------------------- ### Get Shipping Address - Python Example Source: https://developers.vnda.com.br/reference/envio-de-pedido Example of fetching shipping address using Python. This code uses the 'requests' library to make a GET request to the VNDA API. The response data is returned as a dictionary. ```Python import requests # Placeholder for Python code example # order_code = 'your_order_code' # url = f"https://api.vnda.com.br/api/v2/orders/{order_code}/shipping_address" # headers = { # 'accept': 'application/json' # } # # response = requests.get(url, headers=headers) # print(response.json()) ``` -------------------------------- ### Get Shipping Address - Ruby Example Source: https://developers.vnda.com.br/reference/envio-de-pedido Example of fetching shipping address using Ruby. This code utilizes the Net::HTTP library to make a GET request to the VNDA API. The response is parsed as JSON. ```Ruby # Placeholder for Ruby code example # require 'net/http' # require 'uri' # # order_code = 'your_order_code' # uri = URI.parse("https://api.vnda.com.br/api/v2/orders/#{order_code}/shipping_address") # # Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| # request = Net::HTTP::Get.new(uri) # request['accept'] = 'application/json' # # response = http.request(request) # puts JSON.parse(response.body) # end ``` -------------------------------- ### Create or Update Asset - Ruby Example Source: https://developers.vnda.com.br/reference/templates-site-assets This Ruby example demonstrates creating or updating a site asset via the vnda API. It uses the Net::HTTP library to send a POST request, including the asset path and base64 encoded content in the request body. The example highlights setting necessary headers and handling potential API errors. ```ruby require 'net/http' require 'uri' require 'json' def upsert_asset(path, body) uri = URI.parse('https://api.vnda.com.br/api/v2/site_assets/upsert') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') request = Net::HTTP::Post.new(uri.request_uri) request['Accept'] = 'application/json' request['Content-Type'] = 'application/json' request['Authorization'] = 'Bearer YOUR_ACCESS_TOKEN' # Replace with your actual token request.body = { path: path, body: body # Content of the file in base64 }.to_json response = http.request(request) if response.code == '200' puts "Asset upserted successfully: #{response.body}" return JSON.parse(response.body) else puts "Error: #{response.code} - #{response.body}" return nil end end # Example usage: # upsert_asset('path/to/your/asset.html', 'base64encodedcontent==') ``` -------------------------------- ### Cart Installment Schema Definition Source: https://developers.vnda.com.br/reference/patch-api-v2-carts-cart_id-items-id Defines the structure for installment payment details in a cart, including whether interest is applied, the interest rate, the number of installments, and the price per installment. Examples are provided for typical installment scenarios. ```json { "description": "Parcelas para pagamento parcelado", "title": "Parcelas do carrinho", "type": "object", "properties": { "interest": { "type": "boolean", "description": "Identifica se há (`true`) ou não (`false`) juros no parcelamento" }, "interest_rate": { "type": "number", "description": "Taxa de juros do parcelamento" }, "number": { "type": "integer", "description": "Número de parcelas" }, "price": { "type": "number", "description": "Valor de cada parcela" }, "total": { "type": "number", "description": "Valor total das parcelas" } }, "x-examples": { "Primeira parcela": { "interest": false, "interest_rate": 0, "number": 1, "price": 837, "total": 837 }, "Segunda parcela": { "interest": false, "interest_rate": 0, "number": 2, "price": 418.5, "total": 837 } }, "x-readme-ref-name": "Cart_installment.v1" } ``` -------------------------------- ### List Menus API Request (Shell, Node, Ruby, PHP, Python) Source: https://developers.vnda.com.br/reference/menus Demonstrates how to make a GET request to the VNDA API to list all available menus. This includes the endpoint URL and expected headers. The examples are provided for common programming languages to facilitate integration. ```Shell curl --request GET \ --url https://api.vnda.com.br/api/v2/menus \ --header 'accept: application/json' ``` ```Node // Node.js example would go here, likely using 'axios' or 'node-fetch' // Example: // const axios = require('axios'); // // axios.get('https://api.vnda.com.br/api/v2/menus', { // headers: { // 'accept': 'application/json' // } // }) // .then(response => { // console.log(response.data); // }) // .catch(error => { // console.error(error); // }); ``` ```Ruby # Ruby example would go here, likely using 'net/http' or 'httparty' # Example: # require 'httparty' # # response = HTTParty.get('https://api.vnda.com.br/api/v2/menus', headers: { 'accept' => 'application/json' }) # puts response.body ``` ```PHP // PHP example would go here, likely using cURL or Guzzle // Example: // $ch = curl_init(); // // curl_setopt($ch, CURLOPT_URL, 'https://api.vnda.com.br/api/v2/menus'); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); // $headers = array(); // $headers[] = 'Accept: application/json'; // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // // $response = curl_exec($ch); // if (curl_errno($ch)) { // echo 'Error:' . curl_error($ch); // } // curl_close($ch); // echo $response; ``` ```Python # Python example would go here, likely using 'requests' # Example: # import requests # # url = "https://api.vnda.com.br/api/v2/menus" # headers = { # "accept": "application/json" # } # # response = requests.get(url, headers=headers) # print(response.json()) ``` -------------------------------- ### GET /api/v2/carts/{cart_id}/installments Source: https://developers.vnda.com.br/reference/pagamento Calculates the payment installments for the total amount of a shopping cart. It returns information about interest, installment price, and the number of installments available for the given cart. ```APIDOC ## GET /api/v2/carts/{cart_id}/installments ### Description Calculates the payment installments for the total amount of a shopping cart. It returns information about interest, installment price, and the number of installments available for the given cart. ### Method GET ### Endpoint https://api.vnda.com.br/api/v2/carts/{cart_id}/installments ### Parameters #### Path Parameters - **cart_id** (string) - Required - Código identificador `ID` ou `token` do carrinho ### Responses #### Success Response (200) - **interest** (boolean) - Identifica se há (`true`) ou não (`false`) juros no parcelamento - **interest_rate** (number) - Taxa de juros do parcelamento - **number** (integer) - Número de parcelas - **price** (number) - Valor de cada parcela - **total** (number) - Valor total das parcelas #### Error Response (404) - **error** (string) - enum: `not found` - Required - Indicates that the cart was not found. ### Request Example ```json { "example": "Not applicable for GET request body" } ``` ### Response Example #### Success Response (200) ```json [ { "interest": true, "interest_rate": 0.05, "number": 3, "price": 100.00, "total": 300.00 } ] ``` #### Error Response (404) ```json { "error": "not found" } ``` ``` -------------------------------- ### Retrieve Products from Catalog (Python) Source: https://developers.vnda.com.br/reference/produto This Python snippet shows how to retrieve products from the VNDA catalog using the 'requests' library. It makes a GET request to the API endpoint and prints the JSON response. Make sure to install 'requests' (`pip install requests`). ```python import requests url = "https://api.vnda.com.br/api/v2/products" headers = { "accept": "application/json" } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes products = response.json() print(products) except requests.exceptions.RequestException as e: print(f"Error fetching products: {e}") ``` -------------------------------- ### List Clients Python Request Source: https://developers.vnda.com.br/reference/clientes-1 Demonstrates how to list clients using Python's 'requests' library. This code example shows how to construct the GET request, include headers, and handle the JSON response. ```python import requests url = "https://api.vnda.com.br/api/v2/clients" headers = { "accept": "application/json" } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### POST /api/v2/products Source: https://developers.vnda.com.br/reference/post-api-v2-products This endpoint allows you to create a new product in your store's catalog. You need to provide essential information such as reference, name, and optionally description, active status, tags, and product type. ```APIDOC ## POST /api/v2/products ### Description Creates a new product in the store's catalog. ### Method POST ### Endpoint /api/v2/products ### Parameters #### Query Parameters None #### Request Body - **reference** (string) - Required - Product Reference Code - **name** (string) - Required - Product Name - **description** (string) - Optional - Product Description - **active** (boolean) - Optional - Indicates if the product is active (`true`) or inactive (`false`). Defaults to `true`. - **tag_list** (string) - Optional - Comma-separated list of tags associated with the product. Example: `tag1, tag2` - **product_type** (string) - Optional - Type of product. Enum: `product`, `sample`, `subscription`. Defaults to `product`. ### Request Example ```json { "reference": "SKU123", "name": "Example Product", "description": "This is a sample product description.", "active": true, "tag_list": "electronics, gadgets", "product_type": "product" } ``` ### Response #### Success Response (201) - **reference** (string) - Reference code of the created product. - **name** (string) - Name of the created product. - **description** (string) - Description of the created product. - **active** (boolean) - Active status of the product. - **tag_list** (string) - Tags associated with the product. - **product_type** (string) - Type of the product. #### Response Example ```json { "reference": "SKU123", "name": "Example Product", "description": "This is a sample product description.", "active": true, "tag_list": "electronics, gadgets", "product_type": "product" } ``` #### Error Response (404) - **error** (string) - Indicates that the store domain was not found. Example: `not found` #### Error Response (422) - **errors** (object) - Contains validation errors for the fields submitted. The keys are the field names, and the values are arrays of error messages. ``` -------------------------------- ### Get Cart Total Installments Source: https://developers.vnda.com.br/reference/get-api-v2-carts-id-installments Retrieves the installment options for the total amount of a shopping cart. This endpoint is useful for displaying payment options to users during the checkout process. ```APIDOC ## GET /cart/total/installments ### Description Calculates and returns the available installment options for the total amount of a shopping cart. This allows merchants to display payment flexibility to their customers. ### Method GET ### Endpoint /cart/total/installments ### Parameters #### Query Parameters - **cart_id** (string) - Required - The unique identifier for the shopping cart. - **total_amount** (number) - Required - The total amount of the shopping cart for which to calculate installments. - **max_installments** (integer) - Optional - The maximum number of installments to consider. ### Request Example ```json { "example": "/cart/total/installments?cart_id=xyz123&total_amount=100.00&max_installments=12" } ``` ### Response #### Success Response (200) - **installments** (array) - A list of available installment options. - **number_of_installments** (integer) - The number of installments. - **installment_value** (number) - The value of each installment. - **total_value** (number) - The total value for this installment plan. #### Response Example ```json { "example": { "installments": [ { "number_of_installments": 1, "installment_value": 100.00, "total_value": 100.00 }, { "number_of_installments": 2, "installment_value": 50.00, "total_value": 100.00 } ] } } ``` ``` -------------------------------- ### GET /api/v2/carts/{cart_id}/installments Source: https://developers.vnda.com.br/reference/get-api-v2-carts-cart_id-installments Calculates the payment installments for the total value of a cart. This endpoint helps determine how a cart's total can be paid in installments, including information about interest. ```APIDOC ## GET /api/v2/carts/{cart_id}/installments ### Description Calculates the payment installments for the total value of a cart. This endpoint helps determine how a cart's total can be paid in installments, including information about interest. ### Method GET ### Endpoint /api/v2/carts/{cart_id}/installments ### Parameters #### Path Parameters - **cart_id** (string) - Required - Código identificador `ID` ou `token` do carrinho ### Request Example ```json { "example": "No request body for this GET request." } ``` ### Response #### Success Response (200) - **interest** (boolean) - Identifies if there is (`true`) or no (`false`) interest in the installment plan. - **interest_rate** (number) - The interest rate for the installment plan. - **number** (integer) - The number of installments. - **price** (number) - The price of each installment. - **total** (number) - The total price of the installments. #### Response Example ```json [ { "interest": false, "interest_rate": 0, "number": 1, "price": 837, "total": 837 }, { "interest": false, "interest_rate": 0, "number": 2, "price": 418.5, "total": 837 } ] ``` #### Error Response (404) - **error** (string) - Describes the error, typically "not found". #### Response Example ```json { "error": "not found" } ``` ``` -------------------------------- ### POST /api/v2/products Source: https://developers.vnda.com.br/reference/post-api-v2-products-1 Creates a new product in the Vnda E-commerce platform. Requires product name and reference. Supports optional description, active status, and a comma-separated list of tags. ```APIDOC ## POST /api/v2/products ### Description Creates a new product. ### Method POST ### Endpoint /api/v2/products #### Query Parameters None #### Request Body - **name** (string) - Required - The name of the product. - **description** (string) - Optional - The description of the product. - **active** (boolean) - Optional - Whether the product is active. - **reference** (string) - Required - The reference code for the product. - **tag_list** (string) - Optional - A comma-separated list of tags for the product (e.g., "tag1, tag2"). ### Request Example ```json { "name": "Example Product", "description": "This is an example product.", "active": true, "reference": "REF12345", "tag_list": "electronics, gadgets" } ``` ### Response #### Success Response (201) - **id** (integer) - The unique identifier of the created product. - **active** (string) - The active status of the product. - **reference** (string) - The reference code of the product. - **name** (string) - The name of the product. - **description** (string) - The description of the product. - **tag_list** (array of strings) - A list of tags associated with the product. - **slug** (string) - The URL-friendly slug for the product. - **url** (string) - The URL of the product. - **updated_at** (string) - The timestamp when the product was last updated. #### Response Example ```json { "id": 1, "active": "true", "reference": "REF12345", "name": "Example Product", "description": "This is an example product.", "tag_list": [ "electronics", "gadgets" ], "slug": "example-product", "url": "https://api.vnda.com.br/products/example-product", "updated_at": "2023-10-27T10:00:00Z" } ``` #### Error Response (422) - **errors** (object) - An object containing validation errors, where keys are field names and values are arrays of error messages. #### Error Response Example ```json { "errors": { "name": [ "can't be blank" ] } } ``` ``` -------------------------------- ### Calculate Payment Installments (PHP) Source: https://developers.vnda.com.br/reference/pagamento This PHP snippet demonstrates how to calculate payment installments using cURL. It sends a GET request to the VNDA API, specifying the cart ID and the 'accept' header. This is suitable for PHP web applications or scripts. ```php ``` -------------------------------- ### Authentication and Shop Host Source: https://developers.vnda.com.br/reference/get-api-v2-payment_recipients-id Information on how to authenticate your requests using an API token and how to specify the shop host domain. ```APIDOC ## API Authentication and Shop Host ### Description This section details the required headers for API authentication and specifying the shop host. ### Method N/A (Describes headers, not a specific endpoint) ### Endpoint N/A ### Parameters #### Header Parameters - **Authorization** (string) - Required - The authentication token in the format 'Bearer seu_token'. This token can be generated from the admin panel and has no expiration date. Production and testing environment tokens/URLs differ. Refer to [API Token documentation](http://ajuda.vnda.com.br/pt-BR/articles/1506726-chave-token-de-api) and [testing environment documentation](http://ajuda.vnda.com.br/pt-BR/articles/3760960-ambiente-de-testes-staging). - **X-Shop-Host** (string) - Required - The domain of the store, e.g., `www.nomedaloja.com.br`. ``` -------------------------------- ### Calculate Payment Installments (Python) Source: https://developers.vnda.com.br/reference/pagamento This Python snippet demonstrates how to calculate payment installments using the 'requests' library. It sends a GET request to the VNDA API, specifying the cart ID and the 'accept' header. This is ideal for integrating with Python-based applications or scripts. ```python import requests url = 'https://api.vnda.com.br/api/v2/carts/cart_id/installments' headers = { 'accept': 'application/json' } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code} - {response.text}") ``` -------------------------------- ### Product Example Data Source: https://developers.vnda.com.br/reference/get-api-v2-products Provides an example of product data, illustrating the structure and content of a product entry. This includes details like availability, pricing, categories, and variants. ```json { "value": [ { "id": 0, "active": true, "available": true, "category_tags": [ { "tag_type": "string", "name": "string", "title": "string" } ], "description": "string", "discount_id": 0, "html_description": "string", "image_url": "string", "installments": [ 0 ], "min_quantity": "string", "name": "string", "on_sale": true, "plain_description": "string", "price": 0, "rating": { "rating": 0, "votes": 0 }, "reference": "string", "sale_price": 0, "slug": "string", "tag_names": [ "string" ], "updated_at": "string", "url": "string", "variants": [ { "{id}": { "available": true, "available_quantity": 0, "custom_attributes": {} } } ] } ] } ``` -------------------------------- ### Get Cart Shipping Address - Ruby Source: https://developers.vnda.com.br/reference/envio-do-carrinho A Ruby example demonstrating how to fetch a cart's shipping address. It uses the built-in 'Net::HTTP' library to perform the GET request. ```ruby require 'net/http' require 'uri' require 'json' def get_shipping_address(cart_id) uri = URI.parse("https://api.vnda.com.br/api/v2/carts/#{cart_id}/shipping_address") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request['accept'] = 'application/json' begin response = http.request(request) if response.is_a?(Net::HTTPSuccess) JSON.parse(response.body) else puts "Error: #{response.code} - #{response.body}" nil end rescue Net::HTTPError => e puts "HTTP Error: #{e.message}" nil end end # Example usage: # cart_id = "your_cart_id" # address = get_shipping_address(cart_id) # puts address ``` -------------------------------- ### Create Discount using cURL Source: https://developers.vnda.com.br/reference/promo%C3%A7%C3%B5es This cURL example demonstrates how to make a POST request to the VNDA API to create a discount. It includes setting the content type and providing a JSON payload with basic discount parameters like 'enabled' and 'cumulative'. ```Shell curl --request POST \ --url https://api.vnda.com.br/api/v2/discounts \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data '{ "enabled": true, "cumulative": true }' ```