V3 Request HTTP API resources
Method 1: RestAPI block
The RestAPI block is available from version 2.4.12
Using RestAPI block in Cally Square
Fill the RestAPI block as described below:
assuming the response of the request is
{ "userId": 1, "id": 1, "title": "delectus aut autem"}
the application will set following variables:
RESULT_STATUS_CODE "200"
RESULT_STATUS_MESSAGE "OK"
RESULT.userId "1"
RESULT.id "1"
RESULT.title "delectus aut autem"
Method 2: External Script
Create script
Below you can see an example of script written in Perl language, but you can use your favourite language.
If you want to run the following example, make sure that:
- perl is installed in your system
- script dependencies are installed in your system
- yum install perl-CPAN
- cpan install JSON
- example.agi is using needed permissions (execution)
#!/usr/bin/perl -w use strict; use warnings; use JSON qw( decode_json ); my $url = "https://jsonplaceholder.typicode.com/todos/1"; my $curl=`curl -k '$url'`; # { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false } my $decoded = decode_json($curl); my $title = $decoded->{'title'}; print "SET VARIABLE RESULT_TITLE \"$title\"\n"; my $userId = $decoded->{'userId'}; print "SET VARIABLE RESULT_USERID \"$userId\"\n";
The script can be used as reference for your needs and remember to set properly the result of the cURL command:
print "SET VARIABLE <CHANNEL_VARIABLE> \"<VARIABLE>\"\n";
Use script in Cally Square project
The script must be used as Command in AGI block:
And the variable set in the example.agi script will be available in Cally Square project.
As alternative of AGI Cally Square block, you can use System block assigning the result of the script as channel variable.