Example of using the example API?

Discussion in 'Customization & add-ons' started by frybread, Jun 9, 2014.

  1. frybread

    frybread aMember Pro Customer

    Joined:
    Jul 14, 2008
    Messages:
    63
    I'm trying to make a script that will subscribe current users, using the API.

    I copied the example here,

    http://www.amember.com/docs/REST_API_examples

    and put it into a test file,
    test.php

    I changed some of the variables, and ended up with this,

    PHP:
    <?php
    $url 
    'http://www.frybreadssite.com/amember/api/invoices';
       
            
    $vars = array(
                
    '_key'      =>  'DSFwHfakekeyjmK222',  /// fake key, I used my real one
                ///// Invoice Record;
                
    'user_id'  => 5184,
                
    'paysys_id' => 'offline',
                
    'currency'  =>  'USD',
                
    'first_subtotal' => '7.95',
                
    'first_discount'    =>  '0.00',
                
    'first_tax'    =>  '0.00',
                
    'first_shipping'    =>  '0.00',
                
    'first_total'      =>  '7.95',
                
    'first_period'      =>  '1m',
                
    'rebill_times'      =>  99999/// means forever.
                
    'second_subtotal' => '7.95',
                
    'second_discount'    =>  '0.00',
                
    'second_tax'    =>  '0.00',
                
    'second_shipping'    =>  '0.00',
                
    'second_total'      =>  '7.95',
                
    '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]'    =>  '7.95',
                
    'nested[invoice-items][0][first_tax]'    =>  '0.00',
                
    'nested[invoice-items][0][first_shipping]'    =>  '0.00',
                
    'nested[invoice-items][0][first_total]'      =>  '7.95',
                
    '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]'      =>  '7.95',
                
    'nested[invoice-items][0][second_price]'      =>  '7.95',
                
    '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]' => 5184,
                
    '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]' => '7.95',
       
                
    // Access record
                
    'nested[access][0][user_id]' => 5184,
                
    'nested[access][0][product_id]' => 2,
                
    'nested[access][0][transaction_id]' => "test-transaction",
                
    'nested[access][0][begin_date]' => '2014-01-01',
                
    'nested[access][0][expire_date]' => '2015-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);
    And then I uploaded the php file to my server, then accessed it, and nothing happens to user 5184, or anyone else.

    If someone can give me an example of how to use the example, I'd be very grateful!
  2. frybread

    frybread aMember Pro Customer

    Joined:
    Jul 14, 2008
    Messages:
    63
    For anyone curious, support got back to me.

    Code:
    'nested[invoice-items][0][item_title]' => 'Archive',.


    was a typo on amember's example. It should read,

    Code:
    'nested[invoice-items][0][item_title]' => 'Archive',

Share This Page