Difference between revisions of "REST API examples"

From aMember Pro Documentation
Jump to: navigation, search
Line 20: Line 20:
 
curl_setopt($ch, CURLOPT_POST, true);
 
curl_setopt($ch, CURLOPT_POST, true);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
  
 
//execute post
 
//execute post
Line 113: Line 113:
 
curl_setopt($ch, CURLOPT_POST, true);
 
curl_setopt($ch, CURLOPT_POST, true);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));
 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));
curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
+
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
 
//execute post
 
//execute post
 
$result = curl_exec($ch);
 
$result = curl_exec($ch);

Revision as of 06:34, 30 January 2015

  • Add user to aMember via API:
<?php
$url = 'http://YOURDOMAIN.COM/amember/api/users';
 
$fields = array(
    '_key' => 'SECRETKEY',
    '_format' => 'xml',
    'login' => 'USERNAME',
    'pass' => 'PASSWORD',
    'email' => 'EMAIL',
    'name_f' => 'FIRST NAME',
    'name_l' => 'LAST NAME',
);
//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, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
 
//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' => 1,
    '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 until cancel
    '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
    'nested' => array(
        'invoice-items' => array(
            // InvoiceItem record
            array(
                'item_id' => 1, // product_id here;
                'item_type' => 'product',
                'item_title' => 'Archive',
                'item_description' => 'Description of item',
                'qty' => 1,
                'first_discount' => '0.00',
                'first_price' => '22.00',
                'first_tax' => '0.00',
                'first_shipping' => '0.00',
                'first_total' => '22.00',
                'first_period' => '1m',
                'rebill_times' => 99999,
                'second_discount' => '0.00',
                'second_tax' => '0.00',
                'second_shipping' => '0.00',
                'second_total' => '22.00',
                'second_price' => '22.00',
                'second_period' => '1m',
                'currency' => 'USD',
                'billing_plan_id' => 1 // Billing plan within  product, check am_billing_plan table.
            )
        ),
        'invoice-payments' => array(
            // InvoicePayment record
            array(
                'user_id' => 1,
                'paysys_id' => 'offline',
                'receipt_id' => 'test-receipt',
                'transaction_id' => 'test-transaction',
                'currency' => 'USD',
                'amount' => '22.00'
            )
        ),
        'access' => array(
            // Access record
            array(
                'user_id' => 1,
                'product_id' => 1,
                'transaction_id' => "test-transaction",
                'begin_date' => '2012-01-01',
                'expire_date' => '2013-01-01'
            )
        )
    ));
 
//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, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
//execute post
$result = curl_exec($ch);
 
//close connection
curl_close($ch);