Publish triggering wrong Webhook

I’ve noticed for a while that if I have two webhooks with a similar (but different) names a Publish() to one will trigger both, which is far from ideal.

Background
I’ve setup two webhooks for each integration in my application, one pointing to production and one pointing to dev.
My webhook is structured like so:

{
    "event": "envRead",
    "responseTopic": "{{PARTICLE_DEVICE_ID}}/hook-response/{{PARTICLE_EVENT_NAME}}",
    "errorResponseTopic": "{{PARTICLE_DEVICE_ID}}/hook-error-response/{{PARTICLE_EVENT_NAME}}",
    "url": "myurl.io",
    "requestType": "POST",
    "noDefaults": true,
    "rejectUnauthorized": true,
    "responseTemplate": "",
    "json": "{{{PARTICLE_EVENT_VALUE}}}"
}

With the following (abbreviated) changes made for the dev environment:

{
    "event": "envRead_dev",
    "url": "myurl.dev"
}

In my code I have a flag setup so I can easily switch and flash to dev when needed.

//Debug flags
#define devServer true

//Global variables
#if devServer
  const char * const EnvRHook = "envRead_dev";
//other dev integrations
# else
  const char * const EnvRHook = "envRead";
//other prod integrations
#endif

//logic

Particle.publish(EnvRHook, data, PRIVATE, WITH_ACK);

I currently only have one device running to this new webhook and it’s targeting the dev server.
I can see it’s publishing a dev reading but the integration gets triggered twice.

More so If i check the integration page for my prod webhook i see that it was indeed triggered and errored out as expected.
image
While it succeeded when hitting the dev site.

Anyone else experience this kind of thing, and anyone know how to fix it?

That is the intended behaviour. The event name is meant to be a prefix.
Any event that start with that prefix will fire the webhook - just the same as with Paricle.subscribe() handlers.

That’s also documented and can be seen here too

If you want to them to be exclusive you need to have them differ - not just be longer than the other - e.g. envRead_dev vs. envRead_prod would be fine, so would this dev_envRead vs. envRead.

1 Like

That tooltip appears to be the only location that mentions that that field is a prefix and not an exact value.

Given the wording in the webhook guide:





And the wording of Events themselves:

And the use of the term “Event Name” this is a very reasonable (I would even say expected) misunderstanding.

I see the value in having this functionality, but hiding this, IMO very important information, behind a single tooltip feels like a huge oversight.