HTTP Object: Difference between revisions
WikiSysopdi (talk | contribs) No edit summary |
WikiSysopdi (talk | contribs) No edit summary |
||
Line 36: | Line 36: | ||
Example of automating updating the currency data in Sage CRM from an api | Example of automating updating the currency data in Sage CRM from an api | ||
di.addserver("CRM");//our crm server | di.addserver("CRM");//our crm server | ||
Line 91: | Line 90: | ||
} | } | ||
Latest revision as of 11:22, 3 September 2025
The HTTP object is used to make HTTP requests to variosu web api's (REST etc).
Examples:
Consuming a weather api
jint di
var req = HTTP();
req.Url="https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m";
req.Method="GET";
var response = req.Send();
var json = response.JSON;
di.display(response.body);
di.display(json.latitude);
var table=CreateTable();
table.Columns.Add("latitude");
table.Columns.Add("longitude");
table.Rows.Add(json.latitude, json.longitude);
//append to the island
di.push("weather", table, "a");
---
Example of automating updating the currency data in Sage CRM from an api
di.addserver("CRM");//our crm server
var req = HTTP();
req.Url="https://v6.exchangerate-api.com/v6/YOUR_KEY_HERE/latest/EUR";
req.Method="GET";
var response = req.Send();
var json = response.JSON;
di.display(response.body);
//di.display(json.result);//show the full result
di.display(json.conversion_rates.USD);
di.display(json.conversion_rates.CAD);
di.display(json.conversion_rates.GBP);
di.display(json.conversion_rates.AUD);
di.display(json.conversion_rates.ZAR);
//update Sage CRM
if (json.result=="success")
{
var uSQL="update Currency set Curr_Rate='"+json.conversion_rates.USD+"' where Curr_Symbol='$'";
di.nativesql(uSQL);
uSQL="update Currency set Curr_Rate='"+json.conversion_rates.CAD+"' where Curr_Symbol='$CAN'";
di.nativesql(uSQL);
uSQL="update Currency set Curr_Rate='"+json.conversion_rates.GBP+"' where Curr_Symbol='£'";
di.nativesql(uSQL);
uSQL="update Currency set Curr_Rate='"+json.conversion_rates.AUD+"' where Curr_Symbol='$AUD'";
di.nativesql(uSQL);
uSQL="update Currency set Curr_Rate='"+json.conversion_rates.ZAR+"' where Curr_Symbol='ZAR'";
di.nativesql(uSQL);
}