Hello! I need to create a new Order with an API but I can't get it to work. My code so far is: //POST (create a new record (table)) http:API, (with additional body elements, OUCU=****, password=******, client_id=1. latitude=89, longitude=-20). function orderCreated() { let data = { oucu:"xxxxxxx", password:"xxxxxxx", client_id: 1, latitude:89, longitude:-20 }; var formBody = []; for (var property in data) { var encodedKey = encodeURIComponent(property); var encodedValue = encodeURIComponent(data[property]); formBody.push(encodedKey + "=" + encodedValue); } formBody = formBody.join("&"); fetch('httpAPI)', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, body: formBody }) }; So, it must retur: { "status" : "success", "data" : [ { "id":"****", "client_id":"***", "date":*************", "latitude":"****", "longitude":"-******" } ] }
Hello! I need to create a new Order with an API but I can't get it to work.
My code so far is:
//POST (create a new record (table)) http:API, (with additional body elements, OUCU=****, password=******, client_id=1. latitude=89, longitude=-20).
function orderCreated() {
let data = {
oucu:"xxxxxxx",
password:"xxxxxxx",
client_id: 1,
latitude:89,
longitude:-20
};
var formBody = [];
for (var property in data) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(data[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
fetch('httpAPI)', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: formBody
})
};
So, it must retur:
{
"status" : "success",
"data" :
[
{
"id":"****",
"client_id":"***",
"date":*************",
"latitude":"****",
"longitude":"-******"
}
]
}
Step by step
Solved in 2 steps