This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal. |
Can any one help me for sending a JSON data to an API and getting a response from that API. Please provide a sample code for that.
Any updates? @Jvne Dickens @Adwivn Russell
Hello @Tim Gwvhvm can you help here please? Thanks!
@Dvn Mvckvy You can find more details here : https://docs.kony.com/konylibrary/visualizer/viz_api_dev_guide/content/httprequestobject.htm
Though some sections are about file upload/download but you can get the info about how the http request APIs work.
Let us know if this helps.
@Tim Gwvhvm I had gone through this link before but there is no specific code to get the response from the API through JSON.
check the "Downloading a File
" section.
@Tim Gwvhvm I want to extract the response from a JSON. This code doesn't meet that requirement.
Can you update us with the sample Request/Response you are after
function initHome(){
// HTTP Request using open method
frmHome.Button0h18d954dc9a446.onClick = getDataTodos(callback);
}
function getDataTodos(callback){
kony.print(“====>>>> call getDataTodos”);
try{
let req = new kony.net.HttpRequest();
let reqMethod = constants.HTTP_METHOD_GET;
let url = “https://jsonplaceholder.typicode.com/todos/”;
req.open(reqMethod, url);
req.onReadyStateChange = callback;
req.send();
kony.print(“====>>>> sending…”);
} catch(err) {
kony.print(“Error on calling API”);
}
}
function callback(response){
try {
console.log(response.response);
let res = response.response;
res.map(val => {
console.log(val.title);
});
}
catch(err){
console.log(err);
}
}
This is how i tried http request without any params. The response will be print out in console.log.