PHPackages                             renttek/magento2-uuid - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. renttek/magento2-uuid

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

renttek/magento2-uuid
=====================

1.0.0(3y ago)19MITPHPPHP ^8.1

Since Oct 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/renttek/magento2-uuid)[ Packagist](https://packagist.org/packages/renttek/magento2-uuid)[ RSS](/packages/renttek-magento2-uuid/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (11)Versions (2)Used By (0)

Renttek\_Uuid
=============

[](#renttek_uuid)

This module adds the possibility to use Uuids (`ramsey/uuid`/`symfony/uid`) and Ulids (`symfony/uid`) with the Magento Webapi. An example module can be found in the `examples` directory.

Installation
------------

[](#installation)

```
composer require renttek/magento2-uuid

bin/magento module:enable Renttek_Uuid
bin/magento setup:upgrade
```

Usage
-----

[](#usage)

To use the Uuids/Ulids in the magento 2 webapi, you have to use one of the provided objects:

- `\Renttek\Uuid\Api\RamseyUuid\Uuid`
- `\Renttek\Uuid\Api\SymfonyUid\Uuid`
- `\Renttek\Uuid\Api\SymfonyUid\Ulid`

These objects wrap the original Uuid/Ulid objects from the `ramsey/uuid` or `symfony/uid` packages, to allow de-/serialization in the API.

### Uuid/Ulid as url parameter

[](#uuidulid-as-url-parameter)

If you want to pass an Uuid/Ulid as a url parameter, simply add the type hinted parameter to your API Interface:

```
namespace Example\WebapiUuid\Api;

interface FooRepositoryInterface
{
    /**
     * @param \Renttek\Uuid\Api\RamseyUuid\Uuid $id
     *
     * @return \Example\WebapiUuid\Api\Data\FooRamseyUuidInterface
     */
    public function getById(\Renttek\Uuid\Api\RamseyUuid\Uuid $id): \Example\WebapiUuid\Api\Data\FooRamseyUuidInterface;
}
```

And define the URL parameter like a normal string value in the `webapi.xml`:

```

```

The API can then be called normally:

```
GET https://demo.local/rest/V1/uuid-test/ramsey-uuid/92b1a9a7-c78e-477f-9d78-ef5a1f5e741b
```

The type is detected from the interface and the string is validated and converted into an Uuid or Ulid instance.

### Uuid/Ulid as object property type

[](#uuidulid-as-object-property-type)

If you want to use an Uuid/Ulid as a property type, the value is automatically converted to a string when the object is returned from the API:

If your DTO looks like this:

```
