PrestaShop Developer Conference
PrestaShop Developer Conference
Paris, France - November 30, 2023
Let's talk code, commerce and open source.

Warning: You are browsing the documentation for PrestaShop 1.7, which is outdated.

You might want to read an updated version of this page for the current version, PrestaShop 8. Read the updated version of this page

Learn how to upgrade to the latest version.

Retrieve a resource

Now that we have retrieved a list of resources let’s see how to access the details of one resource in particular. In the XML list you can see that each individual resource as a unique ID that you can use to get its details:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="">
        <customer id="1" xlink:href=""/>
        <customer id="2" xlink:href=""/>

We are going to use the same get() method but provide an additional id parameter

Key Value
resource customers
id resource_id (int)

Using PrestaShopWebservice::get

try {
    // creating webservice access
    $webService = new PrestaShopWebservice('', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false);
    // call to retrieve customer with ID 2
    $xml = $webService->get([
        'resource' => 'customers',
        'id' => 2, // Here we use hard coded value but of course you could get this ID from a request parameter or anywhere else
} catch (PrestaShopWebserviceException $ex) {
    // Shows a message related to the error
    echo 'Other error: <br />' . $ex->getMessage();

Returned data

You will receive the same xml as if you request in your browser:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="">
        <id_default_group xlink:href=""><![CDATA[3]]></id_default_group>
        <id_lang xlink:href=""><![CDATA[1]]></id_lang>
        <newsletter_date_add><![CDATA[2013-12-13 08:19:15]]></newsletter_date_add>
        <last_passwd_gen><![CDATA[2020-04-09 13:31:19]]></last_passwd_gen>
        <email><![CDATA[[email protected]]]></email>
        <date_add><![CDATA[2020-04-09 19:31:19]]></date_add>
        <date_upd><![CDATA[2020-04-09 19:31:19]]></date_upd>
        <reset_password_validity><![CDATA[0000-00-00 00:00:00]]></reset_password_validity>
            <groups nodeType="group" api="groups">
                <group xlink:href="">

Access resource fields

You can now loop through this XML object to get each customer field value, or access specific fields individually

$customerFields = $xml->customer->children();
$firstName = $customerFields->firstname;
$lastName = $customerFields->lastname;
echo 'Details for '. $firstName . ' ' . $lastName . PHP_EOL . PHP_EOL;
foreach ($customerFields as $key => $value) {
    echo $key . ': ' . $value . PHP_EOL;