Child pages
  • Chapter 2 - Discovery - Testing access to the web service with the browser

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To test if you have properly configured your access to the web service, access your online shop with the following URL: http://[email protected]/api/, where mypasskey is replaced with the key you created, and myprestashop.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.

Note

Another method is to go directly to the following page of your shop: http://myprestashop.com/api/

The shop should prompt you for a username and a password to enter. The ID is the authentication key and there is no password.

...

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:

Code Block
<?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 'll 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.

Code Block
languagehtml/xml
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
  <api shop_name="MYSHOP">
    <addresses>...</addresses>
    <carriers>...</carriers>
    <cart_rules>...</cart_rules>
    <carts>...</carts>
    <categories>...</categories>
    <combinations>...</combinations>
    <configurations>...</configurations>
    <contacts>...</contacts>
    <content_management_system>...</content_management_system>
    <countries>...</countries>
    <currencies>...</currencies>
    <customer_messages>...</customer_messages>
    <customer_threads>...</customer_threads>
    <customers>...</customers>
    <deliveries>...</deliveries>
    <employees>...</employees>
    <groups>...</groups>
    <guests>...</guests>
    <image_types>...</image_types>
    <images>...</images>
    <languages>...</languages>
    <manufacturers>...</manufacturers>
    <order_carriers>...</order_carriers>
    <order_details>...</order_details>
    <order_discounts>...</order_discounts>
    <order_histories>...</order_histories>
    <order_invoices>...</order_invoices>
    <order_payments>...</order_payments>
    <order_states>...</order_states>
    <orders>...</orders>
    <price_ranges>...</price_ranges>
    <product_feature_values>...</product_feature_values>
    <product_features>...</product_features>
    <product_option_values>...</product_option_values>
    <product_options>...</product_options>
    <product_suppliers>...</product_suppliers>
    <products>...</products>
    <search >...</search>
    <shop_groups>...</shop_groups>
    <shops>...</shops>
    <specific_price_rules>...</specific_price_rules>
    <specific_prices>...</specific_prices>
    <states>...</states>
    <stock_availables>...</stock_availables>
    <stock_movement_reasons>...</stock_movement_reasons>
    <stock_movements>...</stock_movements>
    <stocks>...</stocks>
    <stores>...</stores>
    <suppliers>...</suppliers>
    <supply_order_details>...</supply_order_details>
    <supply_order_histories>...</supply_order_histories>
    <supply_order_receipt_histories>...</supply_order_receipt_histories>
    <supply_order_states>...</supply_order_states>
    <supply_orders>...</supply_orders>
    <tags tags>...</tags>
    <tax_rule_groups>...</tax_rule_groups>
    <tax_r	ules>...</tax_rules>
    <taxes>...</taxes>
    <translated_configurations>...</translated_configurations>
    <warehouse_product_locations>...</warehouse_product_locations>
    <warehouses>...</warehouses>
    <weight_ranges>...</weight_ranges>
    <zones>...</zones>
  </api>
  <api shop_name="MYOTHERSHOP">...</api>
  <api shop_name="YETANOTHERSHOP">...</api>
</prestashop>

As with any XLink-bearing XML file, each resource element leads to more resources, linked from the xlink attribute.

Code Block
<customers xlink:href="http://127.0.0.1/ps1541/api/customers" get="true" put="true" post="true" delete="true" head="true">
  <description xlink:href="http://127.0.0.1/ps1541/api/customers" get="true" put="true" post="true" delete="true" head="true">The e-shop's customers</description>
  <schema xlink:href="http://127.0.0.1/ps1541/api/customers?schema=blank" type="blank"/>
  <schema xlink:href="http://127.0.0.1/ps1541/api/customers?schema=synopsis" type="synopsis"/>
</customers>

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:

Code Block
languagehtml/xml
titleBlank schema
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
  <customer>
	<id></id>
	<id_default_group></id_default_group>
	<id_lang></id_lang>
	<newsletter_date_add></newsletter_date_add>
	<ip_registration_newsletter></ip_registration_newsletter>
	<last_passwd_gen></last_passwd_gen>
	<secure_key></secure_key>
	<deleted></deleted>
	<passwd></passwd>
	<lastname></lastname>
	<firstname></firstname>
	<email></email>
    ...
  </customer>
</prestashop>

Here is an extract of the Customer synopsis schema:

Code Block
languagehtml/xml
titleSynopsis schema
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
  <customer>
    <id_default_group></id_default_group>
    <id_lang format="isUnsignedId"></id_lang>
    <newsletter_date_add></newsletter_date_add>
    <ip_registration_newsletter></ip_registration_newsletter>
    <last_passwd_gen></last_passwd_gen>
    <secure_key format="isMd5"></secure_key>
    <deleted format="isBool"></deleted>
    <passwd required="true" maxSize="32" format="isPasswd"></passwd>
    <lastname required="true" maxSize="32" format="isName"></lastname>
    <firstname required="true" maxSize="32" format="isName"></firstname>
    <email required="true" maxSize="128" format="isEmail"></email>
    ...
  </customer>
</prestashop>

 

Navigating your data

In this tutorial, we are going to base our examples on the Customers tagmanagement of customers through the API, but you can use just about any data

In the Customers element, you should get these attributes and tags:

Code Block

<customers xlink:href="http://myprestashop.com/api/customers" get="true" put="true" post="true" delete="true" head="true">
  <description xlink:href="http://127.0.0.1/ps1541/api/customers" get="true" put="true" post="true" delete="true" head="true">The e-shop's customers</description>
  <schema xlink:href="http://127.0.0.1/ps1541/api/customers?schema=blank" type="blank"/>
  <schema xlink:href="http://127.0.0.1/ps1541/api/customers?schema=synopsis" type="synopsis"/>
</customers> 

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 it their data is accessible.

You can now use the XLink link that shows up on the URL http://myprestashop.com/api/customers and go to it.:

Code Block
 

 

Then, from the client list which is displayed via http://myprestashop.com/store/api/customers, you can access the XLink corresponding to each customer.:

 

Example

The XML file found at http://myprestashop.com/api/customers/1, whose link is found in the list of clients (see above), gives you the properties of customers that have "1" as their ID.

...