Chapter 2 - Discovery - Testing access to the web service with the browser
To test if you have properly configured your access to the web service, access your online shop with the following URL: http://mypasskey@example.com/api/, where mypasskey is replaced with the key you created, and example.com with your shop's URL. Mozilla Firefox is the preferred browser to test access, but any browser able to display XML should do just fine.
The shop should prompt you for a username and a password to enter. The ID is the authentication key and there is no password.
Another method is to go directly to the following page of your shop: http://example.com/api/
Of course, it can also work locally: http://127.0.0.1/ps1541/api/ gives the same result.
The /api/ URL gives you access to the list of resources that you configured in your back-office, with all the permissions you chose to grant. If no permission has been set for the key, than the browser will keep asking you to enter the key indefinitely. If you cannot access some resources, the API might answer with this XML response:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>
Using XLink, you will then be able to access your various resources. XLink associates an XML file to another XML file via a link.
Available resources
The /api/ URL gives you the root of all the resources, in the form of an XML file.
Here it is, extremely simplified. This list is current as of version 1.5.4.1 of PrestaShop. Note that we only show the API resources available for one of the available stores.
In addition, the element contains a description of the resource, and two schemas: a blank one, which you can use to create a new item, and a synopsis one, which is just like the blank one but with a detailed description of what type of data is expected in each element.
Here is an extract of the Customer blank schema:Blank schema
The get, put, post, and delete attributes have the value true, meaning that you have correctly configured the customers resource for the current, and that their data is accessible.
You can now use the XLink link that shows up on the URL http://example.com/api/customers and go to it:Result for http://example.com/api/customers
Then, from the customers list which is displayed via http://example.com/store/api/customers, you can access the XLink corresponding to each customer. This gives you all the informationResult for http://example.com/api/customers/1
The http://example.com/api/customers/1 example is not only available using the HTTP GET method, but also using POST, PUT, DELETE, HEAD.
To add a customer (or any other resource, for that matter), you simply need to GET the XML blank data for the resource (/api/customer?schema=blank), fill it with your changes, and POST the whole XML file to the /api/customers/ URL again. PrestaShop will take care of adding everything in the database, and will return an XML file indicating that the operation has been successful, along with the ID of the newly created customer.
To edit an existing resource: GET the full XML file for the resource you want to change (/api/customers/7), edit its content as needed, then PUT the whole XML file back to the same URL again.