How to generate a UUID

Do we have any way to generate a UUID (v4) from a value, e.g. by using a mapper?
Edit: I found a String:hash mapper, but I cannot find UUIDv4 algorithm…

What I want to achieve is to create a Primary key for a Shopware entity like this:

Hi @kjetil

Unfortunately, there is no such feature at the moment. However, we have already been aware of this requirement, and it’s in our backlog now.

Could you please let us know whether this issue is blocking your integration? If so, you could use public APIs, such as Online UUID Generator Tool to generate a UUID. It might not be an ideal solution, but it could be a workaround for you to proceed further with the integration.

I tested the Shopware API and it accepts a simpler ID as well - just doing string:hash md5 of my key (e.g. 1234 → 81dc9bdb52d04dc20036dbd8313ed055). So that’s good (not blocking integration)! :slight_smile:

This way even suits me better since I can regenerate the ID the same way at any time, so if I first created it from an Akeneo entity, then on later updates I will “know” the Shopware ID based on my Akeneo ID etc.

1 Like

Thank you for letting me know that it’s not blocking your integration.

Regarding the UUID generator, I will let you know once I have an update.

Hi @Gugi,

Is there any update on this? I’m also in need of generating a GUID / UUID in an integration.

It’s not blocking, but curious of the current status.

Hi @tdhollander @kjetil,

Unfortunately, there is no update yet for the functionality to generate the GUID/UUID in Alumio. However, since we now have Code Transformer, we can now generate UUID using JavaScript, as shown below.

Below is the code to generate the UUID:

return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (l) => l === 'x' ? (Math.random() * 16 | 0).toString(16) : ((Math.random() * 16 | 0) & 0x3 | 0x8).toString(16));

Please give it a try and let us know if it works.

1 Like

Hi @Gugi,

Thanks for this example. I was looking into using the code transformer, but was under the impression it wasn’t available in out production environment yet. But I see it is now.

I will take this into consideration as an option, however I did see some posts mentioning that using Math.random is discouraged due to a lowered guarantee of actual uniqueness:
javascript - How do I create a GUID / UUID? - Stack Overflow

Hi @tdhollander

Thank you for pointing out the limitations of Math.random() for generating unique identifiers. It’s correct that Math.random() alone isn’t sufficient for scenarios requiring high uniqueness.

To address this, a more robust approach involves combining a high-resolution timestamp with additional randomness.

const timestamp = Date.now().toString(16).padStart(12, '0'); // Timestamp in hex
const randomHex = () => Math.random().toString(16).substr(2, 8); // 8 random hex digits

const part1 = timestamp.substr(0, 8); // First 8 characters
const part2 = timestamp.substr(8, 4); // Next 4 characters
const part3 = `4${randomHex().substr(0, 3)}`; // Version 4 UUID
const part4 = `${(8 + Math.random() * 4 | 0).toString(16)}${randomHex().substr(0, 3)}`; // Variant
const part5 = randomHex() + randomHex().substr(0, 4); // Final 12 characters

return `${part1}-${part2}-${part3}-${part4}-${part5}`;

This method combines a unique timestamp (ensuring time-based uniqueness) with additional random values. While it still uses Math.random(), the timestamp significantly reduces the likelihood of collisions.

1 Like