RESTful API end-point: /api/packages/

  • Description
    This end-points gives access to the Packages (membership plans) section.
  • Available methods
    GET, POST, PUT, DELETE

 

GET

Get all packages available.

Required headers

  • X-API-KEY
  • Authorization

Payload

Not applicable

Return

Returns a JSON string containing a list of the packages currently available.

Example (php)

The example below retrieves a JSON string ($result) containing all the packages currently available:

$curl = curl_init();
 
// Make sure you insert the correct URL below; this should point to your copy of Pagestead
$url = "http://getpageless.com/api/packages/";
 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
// Replace user and password with a proper account (should have ADMIN persmissions)
curl_setopt($curl, CURLOPT_USERPWD, "user:password"); 
 
// Replace key with a proper access key
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'X-API-KEY: key' )); 
 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
 
$result = curl_exec($curl);
curl_close($curl); 
 
echo $result;

 

POST

Creates a new package.

Required headers

  • X-API-KEY
  • Authorization

Payload

A POST request should have a form-data encoded payload, containing name-value pairs corresponding to attributes of the new package. The following are allowed:

  • name [required, string]: representing the name of the package
  • sites_number [required, number]: representing the number sites allowed in this package
  • price [required, number]: representing the price for the package
  • currency [required, string]: representing the currency (should be a valid three-letter currency code)
  • subscription [required, string]: representing the billing period for the package (should be one of the following: “Weekly”, “Monthly”, “Yearly”, “Every 3 months” or “Every 6 months”)
  • hosting_option [optional, list]: containing up to three options specifying the allowed hosting options for this package (the following options are allowed in the list/array: “Sub-Folder”, “Sub-Domain” and “Custom Domain”, ie [“Sub-Folder”, “Sub-Domain”])
  • export_site: [required, boolean]:  enables or disables the site export functionality
  • ftp_publish: [required, boolean]: enables or disables the ftp upload functionality
  • disk_space: [optional, number]: the allowed number of megabytes for this package
  • templates: [optional, list]: templates allowed for this package (each entry in the list should correspond to a valid template ID, ie [“10”, “20”])
  • blocks: [optional, list]: block categories allowed in this package (each entry in the list should correspond to a valid block category ID, ie [“10”, “20”])
  • status [required, string]: “Active” to make the package active/enabled, “Inactive” to make the package disabled

Return

On success, the end-point will contain a JSON string representing the created package.

Example (php)

The following example create a new package:

$curl = curl_init();
 
// Make sure you insert the correct URL below; this should point to your copy of Pagestead
$url = "http://getpageless.com/api/packages/";
 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// Replace user and password with a proper account (should have ADMIN persmissions)
curl_setopt($curl, CURLOPT_USERPWD, "user:password"); 
 
// Replace key with a proper access key
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-API-KEY: key'));
 
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
$data = array();
$data['name'] = "Package";
$data['sites_number'] = 20;
$data['price'] = 0;
$data['export_site'] = "no";
$data['ftp_publish'] = "yes";
$data['disk_space'] = 250;
$data['currency'] = "USD";
$data['subscription'] = "Monthly";
$data['status'] = "Active";
 
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
 
$result = curl_exec($curl);
 
curl_close($curl);
 
echo $result;

 

 

PUT

Updates an existing package.

Required headers

  • X-API-KEY
  • Authorization

Payload

A PUT request should append a valid package ID to the end-point url, as such: “/api/packages/12”.

A PUT request should have a x-www-form-urlencoded encoded payload, containing name-value pairs corresponding to attributes of the new package. The following are allowed:

  • name [optional, string]: representing the name of the package
  • sites_number [optional, number]: representing the number sites allowed in this package
  • hosting_option [optional, list]: containing up to three options specifying the allowed hosting options for this package (the following options are allowed in the list/array: “Sub-Folder”, “Sub-Domain” and “Custom Domain”, ie [“Sub-Folder”, “Sub-Domain”])
  • export_site: [required, boolean]:  enables or disables the site export functionality
  • ftp_publish: [required, boolean]: enables or disables the ftp upload functionality
  • disk_space: [optional, number]: the allowed number of megabytes for this package
  • templates: [optional, list]: templates allowed for this package (each entry in the list should correspond to a valid template ID, ie [“10”, “20”])
  • blocks: [optional, list]: block categories allowed in this package (each entry in the list should correspond to a valid block category ID, ie [“10”, “20”])
  • status [required, string]: “Active” to make the package active/enabled, “Inactive” to make the package disabled

Return

On success, the end-point will contain a JSON string representing the updated package.

Example (php)

The following example edits an existing package:

$curl = curl_init();
 
// Make sure you insert the correct URL below; this should point to your copy of Pagestead and included the ID for the package you'd like to edit
$url = "http://getpageless.com/api/packages/2";
 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// Replace user and password with a proper account (should have ADMIN persmissions)
curl_setopt($curl, CURLOPT_USERPWD, "user:password");
 
// Replace key with a proper access key
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-API-KEY: key'));
 
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
 
// The array below should contain all the attributes you'd like to change for the selected package
$data = array();
$data['name'] = "Packageee";
 
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
 
$result = curl_exec($curl);
 
curl_close($curl);
 
echo $result;

 

 

DELETE

Deletes a single package from the application.

Required headers

  • X-API-KEY
  • Authorization

Payload

A DELETE request should append a valid package ID to the end-point url, as such: “/api/packages/12”.

Return

On success, the API will return a message confirming deletion of the package.

Example (php)

This example deletes a package with ID = 2:

$curl = curl_init();
 
// Make sure you insert the correct URL below; this should point to your copy of Pagestead and included the ID for the package you'd like to delete
$url = "http://getpageless.com/api/packages/2";
 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// Replace user and password with a proper account (should have ADMIN persmissions)
curl_setopt($curl, CURLOPT_USERPWD, "user:password");
  
// Replace key with a proper access key
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-API-KEY: key'));
 
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
 
$result = curl_exec($curl);
 
curl_close($curl);

echo $result;

 

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.