> For the complete documentation index, see [llms.txt](https://docs.prestashop-project.org/1-5-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.prestashop-project.org/1-5-documentation/english-documentation/developer-guide/developer-tutorials/using-the-prestashop-web-service/chapter-4-retrieve-data-retrieving-a-client.md).

# Chapter 4 - Retrieve Data - Retrieving a Client

**Goal:** List and display information from a customer.\
&#x20;**Difficulty:** \*\
&#x20;**Problem:** How to create a system that allows customers using IDs to retrieve customer records?

## Preparation <a href="#chapter4-retrievedata-retrievingaclient-preparation" id="chapter4-retrievedata-retrievingaclient-preparation"></a>

Duplicate the file `list_the_clients.php` that was created in the previous chapter, rename it to `R-CRUD.php`, and put it at the root of your Web server.\
&#x20;If you didn't finish the previous chapter, duplicate the file `0-CustomersList.php` and rename it `R-CRUD.php`.

In the XML data that we retrieved, which contains the list of clients, we will find all the XLinks providing access to customer information.

```
<customers>
	<customer id="1" xlink:href="http://example.com/api/customers/1" />
</customers>
```

## Example <a href="#chapter4-retrievedata-retrievingaclient-example" id="chapter4-retrievedata-retrievingaclient-example"></a>

The XLink for the `customer` tag with ID 1 is: `http://example.com/api/customers/1`

This link retrieves a new XML file, which contains information about the client who has ID 1.

In order to manage access to different clients, we will associate page identifiers with customers via a `GET` parameter named "id". The link `http://example.com/R-CRUD.php?id=1` we will display the file for customer 1.

We must change the table in the file created in the previous chapter to add a link to future customer files.\
&#x20;We will have to isolate the display from the display list of a particular customer.

In order to do this, we must isolate the display of the list by checking that the "id" `GET` parameter property is not present when viewing your list. We do this using `isset()`.

Calling the web service is exactly the same as displaying the list, except that if you need to add the ID element to the table whose value is the id of a client.

Currently, we are using the `customers` or `clients` resources. If we'd been trying to change the `countries` resources, this ID would have been a country ID.

```
$opt['resource'] = 'customers';
$opt['id'] = $_GET['id'];
$xml = $webService->get($opt);
```

Use `isset()` before setting an ID enables you to easily carry out everything in this chapter.

Accessing resources is performed as above for displaying the list, because the tags that interest us are children of the `customers` tag.

```
$resources = $xml->customers->children();
```

This path can be created in another way (here in an HTML table):

```
foreach ($resources as $key => $resource)
	echo 'Name of field: ' . $key . ' - Value: ' . $resource . '<br />';
```

You now have everything needed to create a script to both list and display information for a particular client.

Try creating this `R-CRUD.php` script. If you encounter any difficulties, follow the example from the `1-Retrieve.php` file, which contains the result to which you should get.

In another chapter, we will see how to filter, sort and limit the number of items displayed in the list. If you're in a hurry to implement these features, you can find more information in Chapter 8.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.prestashop-project.org/1-5-documentation/english-documentation/developer-guide/developer-tutorials/using-the-prestashop-web-service/chapter-4-retrieve-data-retrieving-a-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
