PHP code example of preluigi / ontraport

1. Go to this page and download the library: Download preluigi/ontraport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

preluigi / ontraport example snippets


"    "preluigi/ontraport": "dev-master"
},

$ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );

$my_contact = $ontraport->Contacts->read ( 55 ); //Where 55 is the ID of the contact

print_r ( $my_contact );

/**
 * Ouputs something like:
 *    stdClass Object
 *    (
 *        [code] => 0
 *        [data] => stdClass Object
 *            (
 *                [name] => Customer Name
 *                [price] => 119.95
 *                [id] => 340
 *                [owner] => 2
 *                [firstname] =>
 *                [lastname] =>
 *                [email] =>
 *                [address] =>
 *                [city] =>
 *                [state] =>
 *                [zip] =>
 *                [birthday] =>
 *                [date] => 1448207931
 *                [notes] =>
 *                [status] =>
 *                [category] =>
 *                [lead_source] =>
 *            )

 *        [updates] => Array
 *            (
 *            )

 *        [notifications] => Array
 *            (
 *            )

 *        [account_id] => 27801
 *    )
 **/

$new_product = array (
    'name' => 'An awesome product!',
    'price' => 119.95
);
$result = $ontraport->Products->create ( $new_product );

print_r ( $result );

/**
 * Outputs something like:
 * stdClass Object
 *	(
 *	    [code] => 0
 *	    [data] => stdClass Object
 *	        (
 *	            [name] => An awesome product!
 *	            [price] => 119.95
 *	            [id] => 19
 *	        )
 *
 *	    [updates] => Array
 *	        (
 *	        )
 *
 *	    [notifications] => Array
 *	        (
 *	        )
 *
 *	    [account_id] => 27801
 *	)
 **/


$ontraport->{Object type classname, eg: Contacts}->{method to call}

$ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );
$ontraport->set_version ( '2.1.2' );

array (
  'object' => "https://api.ontraport.com/1/object",
  'objects' => "https://api.ontraport.com/1/objects",
  'objects_meta' => "https://api.ontraport.com/1/objects/meta",
  'objects_tag' => "https://api.ontraport.com/1/objects/tag",
  'form' => "https://api.ontraport.com/1/form",
  'message' => "https://api.ontraport.com/1/message",
  'task_cancel' => "https://api.ontraport.com/1/task/cancel",
  'task_complete' => "https://api.ontraport.com/1/task/complete",
  'transaction_processmanual' => "https://api.ontraport.com/1/transaction/processManual",
  'transaction_refund' => "https://api.ontraport.com/1/transaction/refund",
  'transaction_converttodecline' => "https://api.ontraport.com/1/transaction/convertToDecline",
  'transaction_converttocollections' => "https://api.ontraport.com/1/transaction/convertToCollections",
  'transaction_void' => "https://api.ontraport.com/1/transaction/void",
  'transaction_voidpurchase' => "https://api.ontraport.com/1/transaction/voidPurchase",
  'transaction_reruncommission' => "https://api.ontraport.com/1/transaction/rerunCommission",
  'transaction_markpaid' => "https://api.ontraport.com/1/transaction/markPaid",
  'transaction_rerun' => "https://api.ontraport.com/1/transaction/rerun",
  'transaction_writeoff' => "https://api.ontraport.com/1/transaction/writeOff",
  'transaction_order' => "https://api.ontraport.com/1/transaction/order",
  'transaction_resendinvoice' => "https://api.ontraport.com/1/transaction/resendInvoice"
);

$ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );

$my_endpoints = array (
  'object' => "my_custom_endpoint_for_single_object",
  'objects' => "my_custom_endpoint_for_multiple_objects",
);

$ontraport->set_endpoint ( $my_endpoints ); // Will only change the endpoints defined in $my_endpoints

$ontraport->set_endpoint ( $my_endpoints, true ); // Will substitute all endpoints with only those defined in $my_endpoints


$ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );

/*
 * Outputs the object representing contact with id=55
 */
print_r ( $ontraport->Contacts->read ( 55 ) );

$contacts = new Ontraport\Contacts ( $ontraport );

/*
 * Outputs the same object as above
 */
print_r ( $contacts->read ( 55 ) );

  namespace MyNamespace;  // Using a custom namespace
  extends Ontraport\Contacts
   */
  class Contacts extends Ontraport\Contacts {
    // Overriding the parent method
    public function read ( $id ) {
      $result = parent::read ( $id );
      // Adding the "example_field" to parent called method object result
      $result->data->example_field = 'Test';

      return $result;
    }
  }

  $ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );

  $ontraport->Contacts->read ( 55 );  // Will return the Contact object with ID=55

  /*
   * Changing the base namespace where Ontraport\Ontraport looks for class inclusion
   */
  $ontraport->set_namespace ( 'MyNamespace' );

  $ontraport->Contacts->read ( 55 );  // Will return the Contact object with ID=55 and added field "example_field"

  namespace MyNamespace;  // Using a custom namespace
  extends Ontraport\Contacts
   */
  class Contacts extends Ontraport\Contacts {
    // Overriding the parent method
    public function read ( $id ) {
      $result = parent::read ( $id );
      // Adding the "example_field" to parent called method object result
      $result->data->example_field = 'Test';

      return $result;
    }
  }

  $ontraport = new Ontraport\Ontraport ( 'my_app_id', 'my_app_key' );

  $contacts_object = new Contacts ( $ontraport );

  $contacts_object->read ( 55 );  // Will return the Contact object with ID=55 and added field "example_field"
 create ( array $attrs ) 
 get ( array $ids )