REST API examples
Add user to aMember via API
Section titled “Add user to aMember via API”$url = 'http://example.com/amember/api/users';
$fields = [ '_key' => 'SECRETKEY', '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 datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);
//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Update user to aMember via API
Section titled “Update user to aMember via API”//22 within below URL is ID of user that you want to update$url = 'http://example.com/amember/api/users/22';
$fields = [ '_key' => 'SECRETKEY', 'name_f' => 'FIRST NAME', 'name_l' => 'LAST NAME',];//open connection$ch = curl_init();
//set the url, number of POST vars, POST datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);
//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Add Invoice, Payment, Access
Section titled “Add Invoice, Payment, Access”$url = 'http://example.com/amember/api/invoices';
$vars = [ '_key' => 'SECRETKEY', // Invoice Record 'public_id' => 'TRAX', '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 - paid 0 - pending check Invoice model 'nested' => [ 'invoice-items' => [ // InvoiceItem record [ 'invoice_public_id' => 'TRAX', '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' => [ // InvoicePayment record [ 'invoice_public_id' => 'TRAX', 'user_id' => 1, 'paysys_id' => 'offline', 'receipt_id' => 'test-receipt', 'transaction_id' => 'test-transaction', 'currency' => 'USD', 'amount' => '22.00' ] ], 'access' => [ // Access record [ 'invoice_public_id' => 'TRAX', '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 datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Add access record only
Section titled “Add access record only”$ch = curl_init();$url ="http://www.example.com/amember/api/access";$vars = [ '_key' => 'xxxxxxx', 'user_id' => 1, 'product_id' => 1, 'begin_date' => date('Y-m-d'), // Today 'expire_date' => '2037-12-31' // Lifetime];//set the url, number of POST vars, POST datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Change expiration date for existing access record
Section titled “Change expiration date for existing access record”$ch = curl_init();$url ="http://www.example.com/amember/api/access/5051"; // Access id should be included in url$vars = [ '_key' => 'xxxxx', 'expire_date' => date('Y-m-d') // Set expire date to today's date];//set the url, number of POST vars, POST datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); // Set method to PUT, so API module knows that this is update request.curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Retrieve list of access records for particular user
Section titled “Retrieve list of access records for particular user”$ch = curl_init();$url = "http://www.example.com/amember/api/access?" . http_build_query(['_key' => 'xxxxx', '_filter' => ['user_id' => 1]]);
curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($ch);
//close connectioncurl_close($ch);
$output = json_decode($result, true);Delete existing access record
Section titled “Delete existing access record”$ch = curl_init();$url = "http://www.example.com/amember/api/access/5051?" . http_build_query(['_key' => 'xxxxx']); // Access id should be included in url
curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($ch);
//close connectioncurl_close($ch);Add Product with Billing Plans and assign it to Categories
Section titled “Add Product with Billing Plans and assign it to Categories”$url = 'http://example.com/amember/api/products';
$vars = [ '_key' => 'SECRETKEY',
'title' => 'Product Title', 'description' => 'Product Description', 'start_date' => 'product,group,payment', 'tax_group' => -1,
'nested' => [ 'billing-plans' => [ [ 'title' => 'One Time Payment', 'first_price' => 10, 'first_period' => '1m', 'qty' => 1, 'variable_qty' => 0, 'currency' => 'USD' ], [ 'title' => 'Auto Recurring Subscription', 'first_price' => 10, 'first_period' => '1m', 'second_price' => 10, 'second_period' => '1m', 'rebill_times' => 99999, //until cancelation 'qty' => 1, 'variable_qty' => 0, 'currency' => 'USD' ] ], 'product-product-category' => [ [ 'product_category_id' => 1 ], [ 'product_category_id' => 2 ] ] ]];
//open connection$ch = curl_init();
//set the url, number of POST vars, POST datacurl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($vars));curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"]);//execute post$result = curl_exec($ch);
//close connectioncurl_close($ch);Check access by username and password
Section titled “Check access by username and password”$ch = curl_init();$url = "http://www.example.com/amember/api/check-access/by-login-pass?" . http_build_query([ '_key' => 'xxxxx', 'login' => 'login', 'pass' => 'pass',]);
curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($ch);
//close connectioncurl_close($ch);
$output = json_decode($result, true);Copyright © 2002–2026 www.amember.com. All Rights Reserved.