Example #1
0
} catch (Exception $e) {
    echo "<br>Caught exception when creating contact : " . $e->getMessage() . "<br>";
}
echo "<h1>2. Getting the contact by its phonenumber and updating it.</h1>";
try {
    $contactjson = $pest->get('/contacts/phonenumber/' . $phonenumber);
    $contactarray = json_decode($contactjson, true);
    echo "<br>Retrieved contact with id: " . $contactarray[ContactId] . ", should be identical with " . $contactId . " from part 1.<br>";
    $contactarray[Description] = $description;
    $contactjson = json_encode($contactarray);
    $pest->put('/contacts/' . $contactarray[ContactId], $contactjson);
    echo "<br>Updated contact<br>";
} catch (Exception $e) {
    echo "<br>Caught exception when retrieving or updating contact : " . $e->getMessage() . "<br>";
}
echo "<h1>3. Sending a message to the contact</h1>";
try {
    $messagedata = array('Receivers' => "/contacts/" . $contactId, 'SenderNumber' => $sendernumber, 'Text' => $messagetext);
    $messagejson = $pest->post('/messages', $messagedata);
    $messagearray = json_decode($messagejson, true);
    echo "<br>Message was sent! MessageId: " . $messagearray[MessageId];
} catch (Exception $e) {
    echo "<br>Caught exception when sending message : " . $e->getMessage() . "<br>";
}
echo "<h1>4. Deleting contact.</h1>";
try {
    $pest->delete('/contacts/' . $contactId);
    echo "<br>Deleted contact.<br>";
} catch (Exception $e) {
    echo "<br>Caught exception when deleting contact : " . $e->getMessage() . "<br>";
}