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.
- API Commands
- General Rules
- API Setup
- Sample Code
- create
- Function
- Recommended Fields
- Available Fields
- Sample Code
- Things to Remember
- view
- Function
- Generic Code
- Examples
- edit
- Function
- Required Fields
- Available Fields
- Sample Code
- Things to Remember
- create_subscription
- Function
- Available Fields
- Sample Code
- cancel_subscription
- Function
- Required Fields
- Sample Code
- Things to Remember
API Commands
General Rules
- All dates use the YYYY-MM-DD format
- Status codes:
- A: Active
- C: Paused
- E: Expired
- Lifetime accounts should use date “9999-12-01”
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:
- receive.php
The following files need to be uploaded to the server from which you are making the API call:
- ppsd2_api.php
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:
- Edit the variables located under the “Custom Settings” section of the file.
- $curl_proxy: If cURL requires a proxy on your server, input it here.
- $api_location: The full URL to the “receive.php” file.
- $token: Custom security token required on both ends of the API.
- When establishing a custom token, make sure that it is a random series of numbers and upper/lower case letters, and at least 20 characters in length.
- Example: DFJ38fe9g3F9ekf0GEG8
- $license_key: Your ppSD2 license key.
- This can be found within the “ppSD2/admin/license.php” file on your primary server.
The following changes are required to the “receive.php” file:
- Copy the custom token that was created on the “ppsd2_api.php” file to the $token variable on 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
- email
- username
- expires
Available Fields
- username (blank for a random username)
- password (blank for a random password)
- email
- status (A, C, or E)
- joined (YYYY-MM-DD or blank for today’s date)
- expires (YYYY-MM-DD or “lifetime”)
- flag_exempt (1 or 0)
- lead (1 or 0)
- Any custom field within your database (cAsE SenSiTiVe)
Secure Areas
- Correct format: secure_area_id
- Example for secure area with ID “1”: secure_area_1
- You can find a secure area’s ID from the admin control panel by clicking on “Areas”
Newsletters
- Correct format: newsletter_id
- Example for newsletter with ID “3”: newsletter_3
- You can find a newsletter’s ID from the admin control panel by hovering your mouse over “E-Mail” and clicking “List Newsletters”
Digital Products
- Correct format: digital_product_id
- Example for digital product with ID “5”: digital_product_5
- You can find a digital products’s ID from the admin control panel by hovering your mouse over “Users” and clicking “List 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
- $create_user[’result’] will be a “1” for success or “0” for error.
- $create_user[’message’] will contain a success message or error details.
- Field names are cAsE SeNSiTiVe: first_name is different from First_Name
- Any field submitted that does not exist in the database will be ignored.
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 | 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
- username (username of the account you are edited)
Available Fields
- password
- email
- status (A, C, or E)
- joined (YYYY-MM-DD)
- expires (YYYY-MM-DD or “lifetime”)
- flag_exempt (1 or 0)
- lead (1 or 0)
- Any custom field within your database (cAsE SenSiTiVe)
Secure Areas
- Correct format: secure_area_id
- Example for secure area with ID “1”: secure_area_1
- You can find a secure area’s ID from the admin control panel by clicking on “Areas”
- Removing Access: $info[’secure_area_id’] = “remove”;
Newsletters
- Correct format: newsletter_id
- Example for newsletter with ID “3”: newsletter_3
- You can find a newsletter’s ID from the admin control panel by hovering your mouse over “E-Mail” and clicking “List Newsletters”
- Removing Access: $info[’newsletter_id’] = “remove”;
Digital Products
- Correct format: digital_product_id
- Example for digital product with ID “5”: digital_product_5
- You can find a digital products’s ID from the admin control panel by hovering your mouse over “Users” and clicking “List Digital Products”
- Removing Access: $info[’digital_product_id’] = “remove”;
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
- An account’s username cannot be changed using the API.
- Field names are cAsE SeNSiTiVe: first_name is different from First_Name
- Any field submitted that does not exist in the database will be ignored.
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. |
| No | N/A | ||
| 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
- Subscription ID
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
- Replace the value of $subscription_id with the subscription’s actual ID number.
This page last modifed by admin @ 25 August 2009 05:45. Created on 22 August 2009 11:11 



|