Getting new API token with JSX

Hi I would like to know what is the correct format in JSX or javascript to request a new API token as I am encountering 400 bad request, code listed below (currently using react framework):

var formData = new FormData();

formData.append(‘email’,‘emailname’);

formData.append(‘password’,‘password’);

fetch(‘https://developers.onemap.sg/privateapi/auth/post/getToken’, {
mode: ‘no-cors’,
method: ‘POST’,
headers: {
‘cache-control’: ‘no-cache’,

‘content-type’: ‘multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW’
},
body: formData
})
.then(function (response) {
console.log(“response”,response);
})
.catch(function (error) {
console.log(error);
});

This is an example that you can use.

Regards,
Kai

var form = new FormData();
form.append(“email”, “demo@onemap.sg”);
form.append(“password”, “demo123!”);

var settings = {
“async”: true,
“crossDomain”: true,
“url”: “https://developers.onemap.sg/privateapi/auth/post/getToken”,
“method”: “POST”,
“headers”: {
“cache-control”: “no-cache”,
“postman-token”: “8c262bbe-e61b-f8e7-bbbb-9bf609b1e83c”
},
“processData”: false,
“contentType”: false,
“mimeType”: “multipart/form-data”,
“data”: form
}

$.ajax(settings).done(function (response) {
console.log(response);
});

1 Like