Directus Flow Response Manipulation

How can I use Directus Flows to manipulate certain fields when creating an item, supplement them with data from my Directus, and then return this supplemented data to the application in the response body?

Of course, the same object should also be created in Directus at the same time.

What I tried:

I have an event hook (item.create) triggering my flow and a Transform Payload operation at the end of the chain, looking like that:

{
“name”: “{{item_read_gejrb[0].first_name}} {{item_read_gejrb[0].last_name}}”,
“image_external”: “{{item_read_gejrb[0].avatar_url}}”,
“layer”: “{{$trigger.payload.layer}}”,
“position”: “{{$trigger.payload.position}}”,
“id”: “{{$trigger.payload.id}}”
}

Result:

An empty item is created. Missing all the fields provided. It just exist user_created, date_created and id (not the one I provided)

Log:

Hello, Anton

Try to use the script and create a new payload and use that and see if it works.

Thank you very much for your reply! I get exactly the same result with the script.

Has someone some idea how I can solve this?

Flows are a little tricky and their UX could definitely be improved.

I can’t see @ahmad_quvor script anymore, but basically you want to add the data acquired by previous operations to the original payload that was passed to the flow using a script operation.

module.exports = async function(data) {
	const payload = data.$trigger.payload;
        payload.name = item_read_gejrb[0].last_name;
        payload.image_external= item_read_gejrb[0].avatar_url;
	return payload;
};

The script operation should be the last operation of the chain and the Response Body of the flow should be set to Data of Last Operation

Make sure that item_read_gejrb operation is returning the expected data by inspecting the flow log.

Thank you!!

I don’t know, what I did wrong. But now it’s working with a blocking Flow returning the data of the last operation and a custom script which transforms the payload