Perl

This example uses the Chilkat Perl module - https://www.chilkatsoft.com/perl.asp

GET request

use chilkat();

# unlock the chilkat library
$global = chilkat::CkGlobal->new();
$global->UnlockBundle('UNLOCK CODE');

# initialize the oauth1 details
$oauth1 = chilkat::CkOAuth1->new();
$oauth1->put_ConsumerKey("PROVIDEDKEYHERE");
$oauth1->put_ConsumerSecret("PROVIDEDSECRETHERE");
$oauth1->put_SignatureMethod("HMAC-SHA1");
$oauth1->put_OauthUrl("https://yourwhitelabel.cloudfrontend.net/api/v2/sites/");
$oauth1->put_OauthMethod("GET");
$oauth1->GenNonce(32);

# initialize rest client
$rest = chilkat::CkRest->new();
$bUseQueryParams = 1;
$rest->SetAuthOAuth1($oauth1, $bUseQueryParams);
$rest->AddHeader("Content-Type","application/json; charset=UTF-8");
$success = $rest->Connect("yourwhitelabel.cloudfrontend.net", 443, 1, 1);

# make request
$responseJson = $rest->fullRequestNoBody("GET", "/api/v2/sites/");

# output response
print $rest->get_ResponseStatusCode() . "\r\n";
print $responseJson . "\r\n";

POST request

use chilkat();

# unlock the chilkat library
$global = chilkat::CkGlobal->new();
$global->UnlockBundle('UNLOCK CODE');

# initialize the oauth1 details
$oauth1 = chilkat::CkOAuth1->new();
$oauth1->put_ConsumerKey("PROVIDEDKEYHERE");
$oauth1->put_ConsumerSecret("PROVIDEDSECRETHERE");
$oauth1->put_SignatureMethod("HMAC-SHA1");
$oauth1->put_OauthUrl("https://yourwhitelabel.cloudfrontend.net/api/v2/sites/");
$oauth1->put_OauthMethod("POST");
$oauth1->GenNonce(32);

# initialize rest client
$rest = chilkat::CkRest->new();
$bUseQueryParams = 1;
$rest->SetAuthOAuth1($oauth1, $bUseQueryParams);
$rest->AddHeader("Content-Type","application/json; charset=UTF-8");
$success = $rest->Connect("yourwhitelabel.cloudfrontend.net", 443, 1, 1);

# prepare json body
$jsonReqBody = chilkat::CkJsonObject->new();
$success = $jsonReqBody->AddStringAt(-1, "title", "Example Site");
$success = $jsonReqBody->AddStringAt(-1, "formatted_domain", "somesite.yourdomain.com");
print $jsonReqBody->emit() . "\r\n";

# make request
$responseJson = $rest->fullRequestString("POST", "/api/v2/sites/", $jsonReqBody->emit());

# output response
print $rest->get_ResponseStatusCode() . "\r\n";
print $rest->lastErrorText() . "\r\n";
print $responseJson . "\r\n";

Last updated