Difference between revisions of "REST API examples"

From aMember Pro Documentation
Jump to: navigation, search
Line 22: Line 22:
 
curl_setopt($ch,CURLOPT_URL,$url);
 
curl_setopt($ch,CURLOPT_URL,$url);
 
curl_setopt($ch,CURLOPT_POST,count($fields));
 
curl_setopt($ch,CURLOPT_POST,count($fields));
 +
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 +
 +
//execute post
 +
$result = curl_exec($ch);
 +
 +
//close connection
 +
curl_close($ch);
 +
 +
</source>
 +
 +
* Add Invoice, Payment, Access
 +
 +
<source>
 +
<?php
 +
$url = 'http://YOURDOMAIN.COM/amember/api/invoices';
 +
 +
$vars = array(
 +
 +
    '_key'      =>  'SECRETKEY',
 +
    ///// Invoice Record;
 +
    'user_id'  => 34,
 +
    'paysys_id' => 'offline',
 +
    'currency'  =>  'USD',
 +
    'first_subtotal' => '22.00',
 +
    'first_discount'    =>  '0.00',
 +
    'first_tax'    =>  '0.00',
 +
    'first_shipping'    =>  '0.00',
 +
    'first_total'      =>  '22.00',
 +
    'first_period'      =>  '1m',
 +
    'rebill_times'      =>  99999, /// means forever.
 +
    'second_subtotal' => '22.00',
 +
    'second_discount'    =>  '0.00',
 +
    'second_tax'    =>  '0.00',
 +
    'second_shipping'    =>  '0.00',
 +
    'second_total'      =>  '22.00',
 +
    'second_period'      =>  '1m',
 +
    'is_confirmed'      =>  1,  // Must be 1
 +
    'status'            => 1, // 1 -piad 0 - pending check Invoice model.
 +
 +
//// InvoiceItem record
 +
 +
    'nested[invoice-items][0][item_id]' => 2, //  - product_id here;
 +
    'nested[invoice-items][0][item_type]' => 'product',
 +
    'nested[invoice-items][0][item_title]' => 'Archive',.
 +
    'nested[invoice-items][0][item_description]' => 'Description of item' ,
 +
    'nested[invoice-items][0][qty]' => 1,
 +
    'nested[invoice-items][0][first_discount]'    =>  '0.00',
 +
    'nested[invoice-items][0][first_price]'    =>  '22.00',
 +
    'nested[invoice-items][0][first_tax]'    =>  '0.00',
 +
    'nested[invoice-items][0][first_shipping]'    =>  '0.00',
 +
    'nested[invoice-items][0][first_total]'      =>  '22.00',
 +
    'nested[invoice-items][0][first_period]'      =>  '1m',
 +
    'nested[invoice-items][0][rebill_times]'      =>  99999,
 +
    'nested[invoice-items][0][second_discount]'    =>  '0.00',
 +
    'nested[invoice-items][0][second_tax]'    =>  '0.00',
 +
    'nested[invoice-items][0][second_shipping]'    =>  '0.00',
 +
    'nested[invoice-items][0][second_total]'      =>  '22.00',
 +
    'nested[invoice-items][0][second_price]'      =>  '22.00',
 +
    'nested[invoice-items][0][second_period]'      =>  '1m',
 +
    'nested[invoice-items][0][currency]' => 'USD',
 +
    'nested[invoice-items][0][billing_plan_id]' => 2, // Billing plan within  product, check am_billing_plan table.
 +
 +
    // InvoicePayment record
 +
 +
    'nested[invoice-payments][0][user_id]' => 34,
 +
    'nested[invoice-payments][0][paysys_id]' => 'offline',
 +
    'nested[invoice-payments][0][receipt_id]' => 'test-receipt',
 +
    'nested[invoice-payments][0][transaction_id]' => 'test-transaction',
 +
    'nested[invoice-payments][0][currency]' => 'USD',
 +
    'nested[invoice-payments][0][amount]' => '22.00',
 +
 +
    // Access record
 +
    'nested[access][0][user_id]' => 34,
 +
    'nested[access][0][product_id]' => 2,
 +
    'nested[access][0][transaction_id]' => "test-transaction",
 +
    'nested[access][0][begin_date]' => '2012-01-01',
 +
    'nested[access][0][expire_date]' => '2013-01-01'
 +
 +
);
 +
 +
//url-ify the data for the POST
 +
$fields_string = http_build_query($vars);
 +
//open connection
 +
$ch = curl_init();
 +
 +
//set the url, number of POST vars, POST data
 +
curl_setopt($ch,CURLOPT_URL,$url);
 +
curl_setopt($ch,CURLOPT_POST,count($vars));
 
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  

Revision as of 04:56, 16 August 2012

  • Add user to aMember via API:
<?php
$url = 'http://YOURDOMAIN.COM/amember/api/users';.
 
$fields = array(
            '_key' => 'SECRETKEY',.
            'login' => 'USERNAME',.
            'pass' => 'PASSWORD',.
            'email' => 'EMAIL',.
            'name_f' => 'FIRST NAME',.
            'name_l' => 'LAST NAME',.
            'format' => 'XML',.
    );
 
 
$fields_string  = http_build_query($fields);
//open connection
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 
//execute post
$result = curl_exec($ch);
 
//close connection
curl_close($ch);
  • Add Invoice, Payment, Access
<?php
$url = 'http://YOURDOMAIN.COM/amember/api/invoices';
 
$vars = array(
 
    '_key'      =>  'SECRETKEY',
    ///// Invoice Record;
    'user_id'   => 34,
    'paysys_id' => 'offline',
    'currency'  =>  'USD',
    'first_subtotal' => '22.00',
    'first_discount'    =>  '0.00',
    'first_tax'     =>  '0.00',
    'first_shipping'    =>  '0.00',
    'first_total'       =>  '22.00',
    'first_period'      =>  '1m',
    'rebill_times'      =>  99999, /// means forever.
    'second_subtotal' => '22.00',
    'second_discount'    =>  '0.00',
    'second_tax'     =>  '0.00',
    'second_shipping'    =>  '0.00',
    'second_total'       =>  '22.00',
    'second_period'      =>  '1m',
    'is_confirmed'      =>  1,  // Must be 1
    'status'            => 1, // 1 -piad 0 - pending check Invoice model.
 
//// InvoiceItem record
 
    'nested[invoice-items][0][item_id]' => 2, //  - product_id here;
    'nested[invoice-items][0][item_type]' => 'product',
    'nested[invoice-items][0][item_title]' => 'Archive',.
    'nested[invoice-items][0][item_description]' => 'Description of item' ,
    'nested[invoice-items][0][qty]' => 1,
    'nested[invoice-items][0][first_discount]'    =>  '0.00',
    'nested[invoice-items][0][first_price]'    =>  '22.00',
    'nested[invoice-items][0][first_tax]'     =>  '0.00',
    'nested[invoice-items][0][first_shipping]'    =>  '0.00',
    'nested[invoice-items][0][first_total]'       =>  '22.00',
    'nested[invoice-items][0][first_period]'      =>  '1m',
    'nested[invoice-items][0][rebill_times]'      =>  99999,
    'nested[invoice-items][0][second_discount]'    =>  '0.00',
    'nested[invoice-items][0][second_tax]'     =>  '0.00',
    'nested[invoice-items][0][second_shipping]'    =>  '0.00',
    'nested[invoice-items][0][second_total]'       =>  '22.00',
    'nested[invoice-items][0][second_price]'       =>  '22.00',
    'nested[invoice-items][0][second_period]'      =>  '1m',
    'nested[invoice-items][0][currency]' => 'USD',
    'nested[invoice-items][0][billing_plan_id]' => 2, // Billing plan within  product, check am_billing_plan table.
 
     // InvoicePayment record
 
    'nested[invoice-payments][0][user_id]' => 34,
    'nested[invoice-payments][0][paysys_id]' => 'offline',
    'nested[invoice-payments][0][receipt_id]' => 'test-receipt',
    'nested[invoice-payments][0][transaction_id]' => 'test-transaction',
    'nested[invoice-payments][0][currency]' => 'USD',
    'nested[invoice-payments][0][amount]' => '22.00',
 
    // Access record
    'nested[access][0][user_id]' => 34,
    'nested[access][0][product_id]' => 2,
    'nested[access][0][transaction_id]' => "test-transaction",
    'nested[access][0][begin_date]' => '2012-01-01',
    'nested[access][0][expire_date]' => '2013-01-01'
 
);
 
//url-ify the data for the POST
$fields_string = http_build_query($vars);
//open connection
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($vars));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 
//execute post
$result = curl_exec($ch);
 
//close connection
curl_close($ch);