Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!