Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Created an order and need to use the ID in other function

I need some help with recover data from API.

I just created an order that return:

    request: received obj {status: 'success', data: Array(1)}
index.js:266 200
index.js:267 {"status":"success","data":[{**"id":"541227935"**,"client_id":"1","date":"2022-05-26T13:21:41","latitude":"0.00000000","longitude":"0.00000000"}]}

So, I need to get the id":"541227935" to can use in an other fuction.

This is my code so far, using hard codding to post data into de order created:

    function addWidget(user, pass, orderid, quantity) {
var user = getInputValue("oucu");
var pass = getInputValue("password");
var quantity = document.getElementById("myNumber").value;
console.log("Quantity selected: " + quantity);


//order_id int(11) /* an id from the order table, rquest id to http://1*****.9/openstack/api/orders/1?OUCU=*****&password=*******
var orderid = 541227183;
// widget_id int(11) /* unique id of a widget from widgets table
var widget_id = 2;
//var pence_price = 10;
var pence_price = 13;

let xhr = new XMLHttpRequest();
  

xhr.open("POST", BASE_URL + "order_items");
//http://137.1*****9/openstack/api/order_items?OUCU=*****&password=******&order_id=6
let data = 'OUCU=' + user + '&password=' + pass + '&order_id='+ orderid + '&widget_id='+ widget_id + '&number='+ quantity + '&pence_price='+ pence_price;
xhr.onload = function () {
var obj = JSON.parse(xhr.responseText);
console.log("request: received obj", obj);

if (obj.status == "success") {
alert("Se han añadido: " + quantity);

} else if (obj.message) {
alert(obj.message);
} else {
alert(obj.status + " " + obj.data[1].reason);
}
}

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
};

thank you!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda