Un producto es un objeto que se ofrece en el mercado con la intención de satisfacer la necesidad de un consumidor.
En esta sección aprenderás cómo utilizar la API para insertar una colección de productos.
Para insertar una colección de productos utilizaremos el verbo http POST.
API endpoint exclusivo para partners que trabajen con factura electronica.
Formato de respuesta | JSON |
---|---|
¿Requiere autenticación? | SI |
¿Requiere token? | SI |
¿Requiere Partner key? | NO |
Nombre | Descripción | Tipo del parámetro | Tipo del dato |
---|---|---|---|
rut | Rut de la empresa | Path | String |
numeroSerie | Número de serie del sistema, este valor se obtiene desde el resultado de la autenticación API | Path | Boolean |
productos |
Arreglo de json de productos | Body | Json |
En el parámetro proveedores debes incluir un JSON con la siguiente estructura
Nombre | Tipo | Obligatorio | Descripción |
---|---|---|---|
Codigo | String | SI | Código del Producto |
Nombre |
String | SI |
Nombre del producto |
Descripcion |
String | SI | Descripción del producto |
Cantidad |
Number | SI | Cantidad del producto. El valor mínimo es 1 |
Precio |
Number | SI | Precio del producto. El valor mínimo es 1 |
Inventariable |
boolean | NO | Indicador para marcar producto como inventariable |
[ { "Codigo": "PR0001", "Nombre": "Nombre Producto 1", "Descripcion": "Descripción Producto 1", "Cantidad": 20, "Precio": 15000, "Inventariable": true }, { "Codigo": "PR0002", "Nombre": "Nombre Producto 2", "Descripcion": "Descripción Producto 2", "Cantidad": 15, "Precio": 23000, "Inventariable": false } ]
En este apartado se entrega información importante que debes tener en consideración.
curl --location --request POST 'https://api.nubox.com/Nubox.API/factura/1-9/1/productos' \ --header 'token: f96321b5-4691-4f9a-b097-f34bcf500216' \ --header 'Content-Type: application/json' \ --header 'Cookie: .Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da' \ --data-raw '[ { "Codigo": "PR0001", "Nombre": "Nombre Producto 1", "Descripcion": "Descripción Producto 1", "Cantidad": 20, "Precio": 15000, "Inventariable": true }, { "Codigo": "PR0002", "Nombre": "Nombre Producto 2", "Descripcion": "Descripción Producto 2", "Cantidad": 15, "Precio": 23000, "Inventariable": false } ]'
var settings = { "url": "https://api.nubox.com/Nubox.API/factura/1-9/1/productos", "method": "POST", "timeout": 0, "headers": { "token": "f96321b5-4691-4f9a-b097-f34bcf500216", "Content-Type": "application/json", "Cookie": ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da" }, "data": JSON.stringify([{"Codigo":"PR0001","Nombre":"Nombre Producto 1","Descripcion":"Descripción Producto 1","Cantidad":20,"Precio":15000,"Inventariable":true},{"Codigo":"PR0002","Nombre":"Nombre Producto 2","Descripcion":"Descripción Producto 2","Cantidad":15,"Precio":23000,"Inventariable":false}]), }; $.ajax(settings).done(function (response) { console.log(response); });
var myHeaders = new Headers(); myHeaders.append("token", "f96321b5-4691-4f9a-b097-f34bcf500216"); myHeaders.append("Content-Type", "application/json"); myHeaders.append("Cookie", ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da"); var raw = JSON.stringify([{"Codigo":"PR0001","Nombre":"Nombre Producto 1","Descripcion":"Descripción Producto 1","Cantidad":20,"Precio":15000,"Inventariable":true},{"Codigo":"PR0002","Nombre":"Nombre Producto 2","Descripcion":"Descripción Producto 2","Cantidad":15,"Precio":23000,"Inventariable":false}]); var requestOptions = { method: 'POST', headers: myHeaders, body: raw, redirect: 'follow' }; fetch("https://api.nubox.com/Nubox.API/factura/1-9/1/productos", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
var data = JSON.stringify([{"Codigo":"PR0001","Nombre":"Nombre Producto 1","Descripcion":"Descripción Producto 1","Cantidad":20,"Precio":15000,"Inventariable":true},{"Codigo":"PR0002","Nombre":"Nombre Producto 2","Descripcion":"Descripción Producto 2","Cantidad":15,"Precio":23000,"Inventariable":false}]); var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); } }); xhr.open("POST", "https://api.nubox.com/Nubox.API/factura/1-9/1/productos"); xhr.setRequestHeader("token", "f96321b5-4691-4f9a-b097-f34bcf500216"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Cookie", ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da"); xhr.send(data);
var request = require('request'); var options = { 'method': 'POST', 'url': 'https://api.nubox.com/Nubox.API/factura/1-9/1/productos', 'headers': { 'token': 'f96321b5-4691-4f9a-b097-f34bcf500216', 'Content-Type': 'application/json', 'Cookie': '.Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da' }, body: JSON.stringify([{"Codigo":"PR0001","Nombre":"Nombre Producto 1","Descripcion":"Descripción Producto 1","Cantidad":20,"Precio":15000,"Inventariable":true},{"Codigo":"PR0002","Nombre":"Nombre Producto 2","Descripcion":"Descripción Producto 2","Cantidad":15,"Precio":23000,"Inventariable":false}]) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
var client = new RestClient("https://api.nubox.com/Nubox.API/factura/1-9/1/productos"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("token", "f96321b5-4691-4f9a-b097-f34bcf500216"); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Cookie", ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da"); request.AddParameter("application/json", "[\n {\n \"Codigo\": \"PR0001\",\n \"Nombre\": \"Nombre Producto 1\",\n \"Descripcion\": \"Descripción Producto 1\",\n \"Cantidad\": 20,\n \"Precio\": 15000,\n \"Inventariable\": true\n },\n {\n \"Codigo\": \"PR0002\",\n \"Nombre\": \"Nombre Producto 2\",\n \"Descripcion\": \"Descripción Producto 2\",\n \"Cantidad\": 15,\n \"Precio\": 23000,\n \"Inventariable\": false\n }\n ]", ParameterType.RequestBody); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content);
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.nubox.com/Nubox.API/factura/1-9/1/productos', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'[ { "Codigo": "PR0001", "Nombre": "Nombre Producto 1", "Descripcion": "Descripción Producto 1", "Cantidad": 20, "Precio": 15000, "Inventariable": true }, { "Codigo": "PR0002", "Nombre": "Nombre Producto 2", "Descripcion": "Descripción Producto 2", "Cantidad": 15, "Precio": 23000, "Inventariable": false } ]', CURLOPT_HTTPHEADER => array( 'token: f96321b5-4691-4f9a-b097-f34bcf500216', 'Content-Type: application/json', 'Cookie: .Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
require "uri" require "net/http" url = URI("https://api.nubox.com/Nubox.API/factura/1-9/1/productos") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["token"] = "f96321b5-4691-4f9a-b097-f34bcf500216" request["Content-Type"] = "application/json" request["Cookie"] = ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da" request.body = "[\n {\n \"Codigo\": \"PR0001\",\n \"Nombre\": \"Nombre Producto 1\",\n \"Descripcion\": \"Descripción Producto 1\",\n \"Cantidad\": 20,\n \"Precio\": 15000,\n \"Inventariable\": true\n },\n {\n \"Codigo\": \"PR0002\",\n \"Nombre\": \"Nombre Producto 2\",\n \"Descripcion\": \"Descripción Producto 2\",\n \"Cantidad\": 15,\n \"Precio\": 23000,\n \"Inventariable\": false\n }\n ]" response = https.request(request) puts response.read_body
package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://api.nubox.com/Nubox.API/factura/1-9/1/productos" method := "POST" payload := strings.NewReader(`[ { "Codigo": "PR0001", "Nombre": "Nombre Producto 1", "Descripcion": "Descripción Producto 1", "Cantidad": 20, "Precio": 15000, "Inventariable": true }, { "Codigo": "PR0002", "Nombre": "Nombre Producto 2", "Descripcion": "Descripción Producto 2", "Cantidad": 15, "Precio": 23000, "Inventariable": false } ]`) client := &http.Client { } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("token", "f96321b5-4691-4f9a-b097-f34bcf500216") req.Header.Add("Content-Type", "application/json") req.Header.Add("Cookie", ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }
OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "[\n {\n \"Codigo\": \"PR0001\",\n \"Nombre\": \"Nombre Producto 1\",\n \"Descripcion\": \"Descripción Producto 1\",\n \"Cantidad\": 20,\n \"Precio\": 15000,\n \"Inventariable\": true\n },\n {\n \"Codigo\": \"PR0002\",\n \"Nombre\": \"Nombre Producto 2\",\n \"Descripcion\": \"Descripción Producto 2\",\n \"Cantidad\": 15,\n \"Precio\": 23000,\n \"Inventariable\": false\n }\n ]"); Request request = new Request.Builder() .url("https://api.nubox.com/Nubox.API/factura/1-9/1/productos") .method("POST", body) .addHeader("token", "f96321b5-4691-4f9a-b097-f34bcf500216") .addHeader("Content-Type", "application/json") .addHeader("Cookie", ".Stackify.Rum=4c648f24-1d4f-4817-a602-57005e5e24da") .build(); Response response = client.newCall(request).execute();
"Ejecutado correctamente."
Nombre | Valor |
---|---|
cache-control | no-cache |
content-length | 22 |
content-type | application/json; charset=utf-8 |
date | Thu, 16 Apr 2020 22:53:54 GMT |