HTTP Object: Difference between revisions

From Data Islands
No edit summary
No edit summary
 
(7 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 16: Line 16:
var json = response.JSON;
var json = response.JSON;


//REM show the full response as a string
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");</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(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='£'";


//REM show the response as a formatted object
  di.nativesql(uSQL); 


di.display(json.toString());
  uSQL="update Currency set Curr_Rate='"+json.conversion_rates.AUD+"' where Curr_Symbol='$AUD'";


//REM show part of the respone
  di.nativesql(uSQL); 


di.display(json.latitude);
  uSQL="update Currency set Curr_Rate='"+json.conversion_rates.ZAR+"' where Curr_Symbol='ZAR'";


  di.nativesql(uSQL);   


</blockquote>
}

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);

}