Trigger Master Data v2 - HTTP Trigger

Hi Folks!
I created a trigger to interact with the orders in masterdata v2.
the trigger sends an HTTP request to an app that I developed using nodeJS passing the orderId in the body.
Testing sending the orderId by the postman they work, but by the trigger, they don’t work.
What do I need to do my trigger works?

1 Like

Could you confirm the expected flow for your trigger?

From what I understood:

  • An external app would be responsible for updating the status variable of an entry in the orders data entity.
  • You set up your trigger to monitor the condition status=canceled to then send an HTTP request to the URI in line 17.
  • When you change the status variable of an entry in the orders data entity through Postman, it’s sending the HTTP request as expected.
  • But when you change the status variable of an entry in the order data entity through the external app, it’s not sending the HTTP request.

Did I understand the problem correctly? Also, have you checked that in both situations (Postman and external app) the entry is actually being updated to match the condition?

Just a hunch …

Does the url work without authentication?

Hi, @Saito the URL is working with authentication.
The authentication is happening inside the nodeJS.

Hi @georgebrindeiro!
yes, you understood, but I don’t change the order status by the postman, I said that if I try to make a post to my URL by the postman, passing the orderId by the postman they work.

But when the order status change to canceled, my trigger doesn’t work.

here, you can see my order and his status:

but the trigger doesn’t work.

@iThiagoLessa I didn’t know before, but TIL (today I learned) that we keep all orders in Master Data V2 and we can use them for triggers, as explained in this documentation. Cool!

Could you just check if the status is updated there as well, besides the Orders API? For that, you should do the following GET request:

GET https://motorolaeudevelopment.vtexcommercestable.com.br/api/dataentities/orders/search?_where=id=1217641211547-01&_fields=id,status

If everything goes as expected, you should get this response:

[
    {
        "id": "1217641211547-01",
        "status": "canceled"
    }
]

If this is correct, maybe we need to look into the trigger definition. I copied what you have and it didn’t work for me either. Maybe we’re missing something…

1 Like

@georgebrindeiro I tried with a new order. I requested the cancellation and tried to accomplish the order status besides the order API as you said and the order status changed:

Hi @iThiagoLessa,

I´ve a doubt:

Why not just use the VTEX Order Hook instead of creating a MasterData trigger to notify your app?

Cya!

1 Like

Hi @andremiani!
I’m using this trigger because I need to do this HTTP request passing the orderId to my URL to create a refund to my order when it’s canceled.
And the refund takes a while to release a token that I need to use in the frontend.
Because I did this, this first request is to create a refund from the first moment and needs to be activated when the order status changed.

@georgebrindeiro you sad that can be something in my trigger definition, I’m putting a print here of my configuration to you understand better and see if I wrong something.

I believer there´s a typo in the definition: oderId instead of orderId ?

Things I would do:

  1. Replace the URI with a public one (like https://webhook.site/) to check if the trigger is running with the proper headers.
  2. Check in the VTEX logs for the uri (only the VTEX staff can do it)
1 Like

@Saito I did what you said, and the request send all right;
but it didn’t do the post to my URL…

So, looks like that the trigger is working.

Can you “export as curl” the request from the webhook.site as a curl command, just replace the URL with yours and try to run it? Don´t add or change any header.

@Saito, is this?
how can I execute this?

curl -X ‘POST’ ‘https://webhook.site/e1e4cee9-f076-49da-bb0b-4cdc7c016f79?’ -H ‘connection: close’ -H ‘expect: 100-continue’ -H ‘content-length: 30’ -H ‘host: webhook.site’ -H ‘content-type: application/json; charset=utf-8’ -d $’{“orderId”:“1217892446799-01”}’

Usually on Linux, but you can import it in Postman using Import → Raw text.

Just remember to change https://webhook.site/e1e4cee9-f076-49da-bb0b-4cdc7c016f79 with your url and host: webhook.site with your host. I bet it´s not going to work since there´re no authentication headers.

@Saito, I tried here by the postman and worked well.
Only the trigger is not working.

hmmm… the trigger was supposed to be configured to call the url https://webhook.site/.

So if you can see a post in https://webhook.site/ the trigger is working.

@Saito but why the trigger to my URL doesn’t work?
can be any problem in vtex?

I tried to run with the url from the first picture and got a not found.

@Saito to /moto-create-refund?
did you pass the orderId?
If it is an orderId that I’ve already done the post to my URL you will receive an error.