After you have managed to get some information using the Printfection API and PFQL, you can now display things in your own pages. Maybe a list of products or sections from your account.
But what if you want to actual create or change things using the API. This is where API Methods come in. We've actually already used two methods for authentication and passing a PFQL query. There are many more Methods that can create, modify and delete pretty much anything. Stores, Sections, Products and shopping carts are all manageable using methods.
All methods follow a similar structure, with a number of required and optional parameters that need to be sent with the command. For example, the method to create a new store, Printfection.Stores.create, has two required and one optional parameters:
- name - the name of the store that you are creating (required)
- url - the url extension that you want your store to have e.g. http://www.printfection.com/url (required)
- store_access - 0,1 or 2 to set your new store to open, closed or hidden (optional)
Passing a Method
Passing a method to the Printfection API is very simple, It is really just a matter of constructing a formatted URL that is sent to the Printfection server. The URL consists of your API key, sessionID, the method name and all the parameters that you will be sending. You also need to generate the md5 API signature of the request to ensure that everything is above board.
Using the Printfection.Stores.create method from above, we would create our url as follows. I like to use variables to store my parameters, so first we need to define everything:
$method = "Printfection.Stores.create";
$store_name = "My New Store";
$store_url = "mynewstore";
$store_access = 0;
Then we need to construct our api signature. This is the md5 encrypted version of our command, without the & between each parameter. Remember also from the Authentication process, that all parameters must be in alphabetical order.
$cmd_str = "api_key=".$api_key."method=".$method."name=".$store_name."session_key=".$sessionID."store_access=".$store_access."url=".$store_url."version=1.0".$secret;
$api_sig = md5($cmd_str);
Now we can construct our complete url to send the command, using all of our gathered information:
$q_url = "http://api.printfection.com/restserver.php?api_key=".$api_key."&method=".$method."&name=".$store_name."&session_key=".$sessionID."&store_access=".$store_access."&url=".$store_url."&version=1.0""&version=1.0&api_sig=".$api_sig;
That gives us a complete API url, that when sent as a GET request will return an XML response with either the new store ID, or an error, if things have not been done correctly:
<?xml version="1.0" encoding="UTF-8"?>
You can read more about methods in the Methods documentation.