HTTP Object: Difference between revisions
WikiSysopdi (talk | contribs) No edit summary |
WikiSysopdi (talk | contribs) No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The HTTP object is used to make HTTP requests to variosu web api's. | The HTTP object is used to make HTTP requests to variosu web api's (REST etc). | ||
Line 5: | Line 5: | ||
Consuming a weather api<blockquote>jint di | Consuming a weather api<blockquote>jint di | ||
var req = HTTP(); | var req = HTTP(); | ||
req.Url="https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m"; | |||
req.Url="<nowiki>https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.405&hourly=temperature_2m</nowiki>"; | |||
req.Method="GET"; | req.Method="GET"; | ||
var response = req.Send(); | var response = req.Send(); | ||
var json = response.JSON; | var json = response.JSON; | ||
di.display(response.body); | di.display(response.body); | ||
di.display(json.latitude); | di.display(json.latitude); | ||
var table=CreateTable(); | var table=CreateTable(); | ||
table.Columns.Add("latitude"); | table.Columns.Add("latitude"); | ||
table.Columns.Add("longitude"); | table.Columns.Add("longitude"); | ||
table.Rows.Add(json.latitude, json.longitude); | table.Rows.Add(json.latitude, json.longitude); | ||
//append to the island | //append to the island | ||
</blockquote> | di.push("weather", table, "a");</blockquote> | ||
--- | |||
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); | |||
} |
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);
}