PHPackages                             xmlworld/api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. xmlworld/api-client

ActiveLibrary[API Development](/categories/api)

xmlworld/api-client
===================

Simple connection to the xml.world API

v1.0.2(2y ago)1920MITPHPPHP ^8.1

Since Jul 28Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/XMLWorld/api-client)[ Packagist](https://packagist.org/packages/xmlworld/api-client)[ Docs](https://xml.world)[ RSS](/packages/xmlworld-api-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

api-client
==========

[](#api-client)

Simple connection to the xml.world API

Instalation
-----------

[](#instalation)

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require xml-world/api-client

```

Description
-----------

[](#description)

This library provides a quick way to integrate your booking system with the XML.world API.

You will be able to search for hotel accommodation scoped by several criteria, to book rooms, to check bookings, to update the reference as a trade, and to cancel it if needed.

The API will return and exhaustive summary of your booking.

Use
---

[](#use)

You first need to apply for trading credentials from XML World.

Once you have them, you can start the API like this:

```
$xmlClient = new XMLClient(login: 'login', password: 'password');
```

The XMLClient exposes object exposes 5 methods from the API at XML World.

### Search request

[](#search-request)

With this request, we send the criteria of our search in order to retrieve the list of stock that fulfills them.

We make use of the **SearchDetails** class which accepts params like *arrivalDate*, *duration*, *regionID*, *roomRequests**properties*, *propertyID*, *mealBasisID*, *minStarRating*, *minimumPrice*, and *maximumPrice*.

```
$searchDetails = new SearchDetails(
	arrivalDate: '2023-09-01',	        // arrival date
	duration: 5,				// duration in days
	roomRequests: new RoomRequests(		// list of rooms
		RoomRequest::fromAges(2),
		RoomRequest::fromAges(
			1,		        // number of adults
			16,		        // age of first child (variadic)
			8,		        // age of second child
			2		        // age of third child
		),
	),
	properties: new Properties(19, 21),	// list of properties if searching for some
	propertyID: null,			// if only one we can use this param, but they exclude each other
	mealBasisID: 0,				// meal basis
	minStarRating: 0,			// filter by star rating
	minimumPrice: 0,			// filter by minimum price
	maximumPrice: 0				// filter by max price
);
```

The params *roomRequests* and *properties* are lists of room requested and properties. We express those lists with the objects **RoomRequests** and **Properties**.

**RoomRequests** accepts a list or **RoomRequest** objects where we specify the number of adults and the ages of non-adult visitors.
Each **RoomRequest** instance is a different room we request for.

**Properties** accepts a list of property IDs. It is used when we request for several hotels. If we are only interested in one hotel we can leave this param **null** and use *propertyID*. Both parameters are mutually exclusive.

The example is searching for rooms from the properties whose IDs are **19** and **21** two rooms, one for two adults and another run for an adult with 3 underage. The system will deduce that the 2-year-old child is actually an infant.

Finally, we post the request:

```
try {
	$result = $xmlClient->search(searchDetails: $searchDetails);
} catch (Throwable $e) {

}
```

In **$result** we get the outcome of the request. It is a **SearchResponse** object. If the **ReturnStatus** is true, it will bring a list of rooms that match our searches in a **PropertyResults** object or an error message otherwise.

### Book request

[](#book-request)

With the **roomIDs** we obtain from the previous request now we can book the rooms.

In order to do that, we construct a **BookDetails** object. This object accepts some of the same params of the **SearchDetails** object like *arribalDate* and *duration* and further params like *tradeReference*, *totalPrice*, *leadGuest*, *roomBookings*.

```
$bookingDetails = new BookDetails(
	arrivalDate: '2023-11-01',
	duration: 5,
	tradeReference: 'TEST_REF',
	totalPrice: 1040,
	leadGuest: new LeadGuest(
		firstName: 'TestLeadFName',
		lastName: 'TestLeadLName',
		title: 'Mr'
	),
	roomBookings: new RoomBookings(
		new RoomBooking(
			roomID: 20011,
			mealBasisID: 6,
			adults: 2,
			children: 0,
			infants: 0,
			guests: new Guests(
				new Guest(
					type: 'Adult',
					firstName: 'TestGuestFName',
					lastName: 'TestGuestLName',
					title: 'Mrs',
					age: null,
					nationality: 'French'
				)
			)
		),
	)
);
```

The names tell what those params are for.

It is important to mention that **totalPrice** is optional but advisable to use. It makes sure that we book at exactly the specified price if it's still available, otherwise it will book at whatever the curren price is.
This is to avoid the scenario where we do a search and get rooms and prices, but the book later and the price has changed, and it could be both lower and higher.

The *leadGuest* param admits a **LeadGuest** object which has to have *firstName*, *lastName* and *title* at minimum but it can have more details. This is the first guest, and it's assumed that goes in the first room of the book.

The *roomBookings* param admits a **RoomBookings** object, which is a list of rooms and accepts one or more **RoomBooking** objects.

Each **RoomBooking** object has the *roomID*, *mealBasisID*, which are the room and meal plan codes from the previous search request.

Then the *adults*, *children* and *infants*, which are the number of each for this room.

Finally, *guests* which accepts a **Guests** object that represents the lists of guests for this room.

If the room only has the lead guest, we can set **null** and if there are more guests along, we don't need to include it here.

Each **Guest** object has *type* whether adult, child or infant. The *firstName* and *lastName*. The *age* which is **null** if it's an adult and specified if a child. And the nationality.

Now we can post the book:

```
try {
	$result = $xmlClient->book(bookingDetails: $bookingDetails);
} catch (Throwable $e) {

}
```

The var *$result* will be a **BookResponse** object which again, if **ReturnStatus** is **true**, *bookingDetails*will be a **BookingDetails** object with the list of rooms we just booked, their special offers, supplements, taxes, cancellation policies if any and hotel details as well as the booking reference at XML World. An error message otherwise.

### Booking request

[](#booking-request)

Booking request is for retrieving the current status of our booking at XML World.

```
try {
	$result = $xmlClient->booking(reference: $bookingReference);
} catch (Throwable $e) {
}
```

We provide the XML World booking reference we got from the book request, and we get a **BookingResponse** object that is identical to the **BookResponse** object from the book request.

### Booking update request

[](#booking-update-request)

Booking update request is for setting the trade reference.

```
try {
	$result = $xmlClient->bookingUpdate(reference: $bookingReference, tradeReference: $tradeReference);
} catch (Throwable $e) {
}
```

The method accepts the booking reference given in the **BookRequest** or **BookingRequest** requests and the trade reference. It returns a **BookingUpdateRequestResponse** object that holds the same data as **BookResponse**.

### Cancel request

[](#cancel-request)

With the Cancel request, we do that, cancel the booking.

```
try {
	$result = $xmlClient->cancel(reference: $bookingReference, reason: $cancellationReason);
} catch (Throwable $e) {
}
```

The method accepts the booking reference given in the **BookRequest** or **BookingRequest** requests and the trade reference. It returns a **CancelResponse** that in principle is like an **BookResponse** but informing about the cancellation success.

Once we cancel a booking, **BookingRequest** returns a **BookingResponse** object that holds the same details as this **CancelResponse**.

Development environment
-----------------------

[](#development-environment)

XMLClient supports two environments, live (by default), and devel.

Live attacks the API in production, and the calls produce real results and bookings.

Devel attacks our staging environment and the data might mirror production, but bookings don't have a real effect.

To activate the devel environment, do this:

```
$env = XMLClient::ENV_DEV;

$xmlClient = new XMLClient(login: $login, password: $password, env: $env);
```

You just need to specify the dev environment by passing the constant **XMLClient::ENV\_DEV** as third parameter.

If you ever need to request a different server in your development environment for tests purposes, you can do so this way:

```
XMLClient::setDevURL('your own dev url');
```

Logging
-------

[](#logging)

XMLClient also provides a way to log calls and responses.

In order to do that, you need to implement the Interface Logger:

```
$myLogger = function($payload){
	echo $payload;
};

//you can implement the Logger interface to inject your logging implementation in the client.
$logging = new class($myLogger) implements Logger
{
	protected Closure $myLogger;

	public function __construct(Closure $myLogger)
	{
		$this->myLogger = $myLogger;
	}

	public function logRequest(string $log): void
	{
		($this->myLogger)($log);
	}

	public function logResponse(int $statusCode, string $log): void
	{
		($this->myLogger)($log);
	}
};

$xmlClient = new XMLClient(login: $login, password: $password, env: $env, logger: $logging);
```

For example, we build this anonymous class that implements **Logger** and injects whatever logging object we use as a forth parameter.

Examples
--------

[](#examples)

you can find examples of use in the folder examples/

1. For searching, in **search\_example.php**.
2. For booking, in **book\_example.php**.
3. For retrieving a booking, in **booking\_example.php**.
4. For updating a booking, in **booking\_update\_example.php**.
5. For canceling a booking, in **cancel\_example.php**.
6. for logging injection, in **logging\_injection\_example.php**.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance57

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1025d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd6466be2d3248a487578742aff7ebfe52deb3eda1fdd280f0d16dfc215b38fb?d=identicon)[XML World](/maintainers/XML%20World)

---

Top Contributors

[![FedericoRoviralta](https://avatars.githubusercontent.com/u/120378314?v=4)](https://github.com/FedericoRoviralta "FedericoRoviralta (31 commits)")[![XMLWorld](https://avatars.githubusercontent.com/u/140537972?v=4)](https://github.com/XMLWorld "XMLWorld (2 commits)")[![pub007](https://avatars.githubusercontent.com/u/3847796?v=4)](https://github.com/pub007 "pub007 (1 commits)")

---

Tags

httpsapiclientxml

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xmlworld-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/xmlworld-api-client/health.svg)](https://phpackages.com/packages/xmlworld-api-client)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[resend/resend-php

Resend PHP library.

574.7M21](/packages/resend-resend-php)[crowdin/crowdin-api-client

PHP client library for Crowdin API v2

611.5M5](/packages/crowdin-crowdin-api-client)[mozex/anthropic-laravel

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

71226.4k1](/packages/mozex-anthropic-laravel)[markrogoyski/numverify-api-client-php

Numverify API Client for PHP

1220.9k](/packages/markrogoyski-numverify-api-client-php)[azuracast/php-api-client

An API client library for the AzuraCast API

311.3k](/packages/azuracast-php-api-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
