Home > API > PHP API examples
login

© Montastic

Google

PHP example - deleting a checkpoint  

Example code:

<?php
$url = "https://www.montastic.com/checkpoints/destroy/9831";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, "ivaylo@metadot.com:111111");  
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-type: application/xml'));
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $httpcode;
echo $result;
?>

In case of success, $httpcode will be 200 and $result will be empty.

In case of error, $httpcode will be 404 or 500, and $result will be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>No foundo.</error>
</errors>

 

PHP example - updating a checkpoint  

Example code:

<?php
$url = "https://www.montastic.com/checkpoints/update/9813";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "<checkpoint><name>user@example.com</name></checkpoint>"); // add POST fields
curl_setopt($ch, CURLOPT_USERPWD, "user@example.com:111111");  
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-type: application/xml'));


$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);


echo $httpcode;
echo $result;
?>

In case of success, $httpcode will be 200, and $result will empty.

In case of error, $httpcode can be 422 (Unprocessable Entity) or 404, and $result will be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>Record not found</error>
</errors>

PHP example - getting checkpoint info  

Example code:

<?php
$url = "https://www.montastic/checkpoints/show/9813";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "user@example.com:111111");  
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-type: application/xml'));
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $httpcode;
echo $result;
?>

In case of success, $httpcode will be 200 and 404 if the id is not found.