Sample code for 30+ languages & platforms
Perl Requires Chilkat v11.0.0+

Activix CRM Create a Communication

See more Activix CRM Examples

Create a communication. Returns the created communication.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

my $http = Chilkat2::Http->new;

$http->AuthToken('ACCESS_TOKEN');

$http->Accept('application/json');

# The following JSON is sent in the request body:

# {
#   "lead_id": "LEAD_ID",
#   "method": "phone",
#   "type": "outgoing",
#   "call_status": "calling"
# }

# Use this online tool to generate the code from sample JSON:
# Generate Code to Create JSON

my $jsonRequestBody = Chilkat2::JsonObject->new;
$jsonRequestBody->UpdateString('lead_id', 'LEAD_ID');
$jsonRequestBody->UpdateString('method', 'phone');
$jsonRequestBody->UpdateString('type', 'outgoing');
$jsonRequestBody->UpdateString('call_status', 'calling');

my $url = 'https://crm.activix.ca/api/v2/communications';

my $resp = Chilkat2::HttpResponse->new;
my $success = $http->HttpJson('POST', $url, $jsonRequestBody, 'application/json', $resp);
if (!$success) {
    print $http->LastErrorText, "\n";
    exit;
}

print 'Response Status Code: ', $resp->StatusCode, "\n";

my $jsonResponse = Chilkat2::JsonObject->new;
$jsonResponse->Load($resp->BodyStr);
$jsonResponse->EmitCompact(0);
print $jsonResponse->Emit(), "\n";

if ($resp->StatusCode >= 300) {
    print "Failed.\n";
    exit;
}

# Sample output...
# (See the parsing code below..)
#
# Use the this online tool to generate parsing code from sample JSON:
# Generate Parsing Code from JSON

# {
#   "data": {
#     "id": 5411998,
#     "created_at": "2019-06-10T13:01:40+00:00",
#     "updated_at": "2019-06-10T13:01:40+00:00",
#     "lead_id": 7135833,
#     "user_id": 13705,
#     "method": "phone",
#     "type": "outgoing",
#     "email_subject": null,
#     "email_body": null,
#     "email_client": null,
#     "email_user": null,
#     "call_duration": null,
#     "call_phone": null,
#     "call_status": "calling"
#   }
# }
#

my $dataId = $jsonResponse->IntOf('data.id');
my $dataCreated_at = $jsonResponse->StringOf('data.created_at');
my $dataUpdated_at = $jsonResponse->StringOf('data.updated_at');
my $dataLead_id = $jsonResponse->IntOf('data.lead_id');
my $dataUser_id = $jsonResponse->IntOf('data.user_id');
my $dataMethod = $jsonResponse->StringOf('data.method');
my $dataType = $jsonResponse->StringOf('data.type');
my $dataEmail_subject = $jsonResponse->StringOf('data.email_subject');
my $dataEmail_body = $jsonResponse->StringOf('data.email_body');
my $dataEmail_client = $jsonResponse->StringOf('data.email_client');
my $dataEmail_user = $jsonResponse->StringOf('data.email_user');
my $dataCall_duration = $jsonResponse->StringOf('data.call_duration');
my $dataCall_phone = $jsonResponse->StringOf('data.call_phone');
my $dataCall_status = $jsonResponse->StringOf('data.call_status');