You are viewing version #11 of a page entitled Api. The page Owner is admin and the last changes were made by admin 12 months ago. There are 1525 words in this revision and it has been viewed 586 times.
This page is Protected from any changes.

Click to hide
Contents (hide)

API Commands

General Rules

API Setup

The following files need to be uploaded to the “ppSD2/api” folder on the primary server where your ppSD2 control panel is located:

The following files need to be uploaded to the server from which you are making the API call:

When creating a custom PHP script that will use the API, always load the ppsd2_api.php file:

require "ppsd2_api.php";
$ppsd2api = new ppsd2;

The following changes are required to the “ppsd2_api.php” file:

The following changes are required to the “receive.php” file:

Sample Code

Sample PHP code is provided with the API ZIP file.

create

Function

Create a user or lead within ppSD2.

Recommended Fields

Available Fields

Secure Areas
Newsletters
Digital Products

Sample Code

$info = array();
$info['username'] = 'johndoe';
$info['email'] = 'john@doe.com';
$info['status'] = 'A';
$info['city'] = 'Chicago';
$info['country'] = 'USA';
$info['secure_area_1'] = '1';
$info['secure_area_2'] = '1';
$info['newsletter_1'] = '1';
$info['digital_product_1'] = '1';
$info['digital_product_4'] = '1';
$create_user = $ppsd2api->create($info);
if ($create_user['result'] == "1") {
  echo "Success: " . $create_user['message'];
} else {
  echo "Error: " . $create_user['message'];
}

Things to Remember

view

Function

Access a user or lead’s account information.

Generic Code

$userinfo = $ppsd2api->view("**username**","**csv of fields**");

Examples

Presume you have the following database:

username email status joined expires address1 address2 city
johndoe john@doe.com A 2009-05-01 2010-05-01 15 S State St Unit 900 Chicago
janedoe jane@doe.com C 2009-08-15 9999-12-01 200 Harlem Ave New York
chrisdoe chris@doe.com E 2007-10-07 2009-01-15 2400 Fullerton Ave San Diego

Example 1
$userinfo = $ppsd2api->view("johndoe","");

Returned: An array will all of the user’s information.

Example 2
$userinfo = $ppsd2api->view("janedoe","email,status,address1");

Returned: An array with the email, status, and address1. You can access this information using the following:

echo "<li>E-Mail:" . $userinfo['email'];
echo "<li>Status:" . $userinfo['status'];
echo "<li>Address Line 1:" . $userinfo['address1'];
Example 3
$userinfo = $ppsd2api->view("paulsmith","email,city,expires");

Returned: Nothing, since the username “paulsmith” does not exist in the database.

edit

Function

Edit a user’s account.

Required Fields

Available Fields

Secure Areas
Newsletters
Digital Products

Sample Code

$info = array();
$info['username'] = 'ascadnet'; // This is the username you are editing
$info['email'] = 'sales@ascad.net'; // Updates the "email"
$info['first_name'] = 'Change'; // Updates the "first_name" field
$info['secure_area_1'] = 'remove'; // Removes access to secure area ID "1"
$info['secure_area_2'] = '1'; // Adds access to secure area ID "2"
$info['newsletter_3'] = 'remove'; // Removes access to newsletter ID "3"
$info['newsletter_6'] = '1'; // Adds access to newsletter ID "6"
$info['digital_product_1'] = 'remove'; // Removes access to digital product ID "1"
$info['digital_product_2'] = '1'; // Adds access to digital product ID "2"
$edit_user = $ppsd2api->edit($info);
if ($edit_user['result'] == "1") {
  echo "Success: " . $edit_user['message'];
} else {
  echo "Error: " . $edit_user['message'];
}

Things to Remember

create_subscription

Function

Creates a subscription for an existing user and adds a credit card to the user’s account.

Available Fields

The following fields need to be passed in an array entitled “info”.

Field Name Required? Format What Is It?
username Yes N/A The account username for which the subscription is being setup.
product_id Yes Numerical Value The ID of the subscription product.
cc_number Yes 4111111111111111 Credit card number. No spaces or dashes.
cc_exp_year Yes YY Credit card expiration date (year).
cc_exp_month Yes MM Credit card expiration date (month).
cc_cvm Yes 3 or 4 digits Credit card security code.
firstname Yes N/A Billing information: first name.
lastname Yes N/A Billing information: last name.
address1 No N/A Billing information: address line 1.
address2 No N/A Billing information: address line 2.
city No N/A Billing information: city.
state No Two letter representation. Billing information: state.
zip No N/A Billing information: ZIP code.
country No N/A Billing information: country.
email No N/A E-mail
phone No N/A Phone
next_renew No YYYY-MM-DD Date when subscription should start being charged. Leave blank to start charging today.
total No 50.00 Recurring subscription total. Leave blank to use the price of the “product_id”.

Sample Code

$info = array();
$info['username'] = "ascadnet";
$info['product_id'] = "6";
$info['cc_number'] = "4111111111111111";
$info['cc_exp_year'] = "12";
$info['cc_exp_month'] = "04";
$info['cc_cvm'] = "123";
$info['firstname'] = "John";
$info['lastname'] = "Doe";
$info['address1'] = "123 Street";
$info['address2'] = "Unit 911";
$info['city'] = "Chicago";
$info['state'] = "IL";
$info['zip'] = "10009";
$info['country'] = "USA";
$info['email'] = "info@ascad.net";
$info['phone'] = "1-123-123-1234";
$info['next_renew'] = ""; // Leave blank to start charging today
$info['total'] = ""; // Leave blank for product total
$create_subscription = $ppsd2api->create_subscription($info);
if ($create_subscription['result'] == "1") {
  echo "Success: " . $create_subscription['message'];
} else {
  echo "Error: " . $create_subscription['message'];
}

cancel_subscription

Function

Cancels a subscription.

Required Fields

Sample Code

$subscription_id = "1";
$cancel_subscription = $ppsd2api->cancel_subscription($subscription_id);
if ($cancel_subscription['result'] == "1") {
  echo "Success: " . $cancel_subscription['message'];
} else {
  echo "Error: " . $cancel_subscription['message'];
}

Things to Remember

This page last modifed by admin @ 25 August 2009 05:45. Created on 22 August 2009 11:11 Protected Page