Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda