webhooks
webhooks copied to clipboard
Webhook data returns wrong siteId
Description
We use craft CMS as a headless CMS and the GraphQL api to get the content. With the Webhook plugin we send webhooks to the application to clear the cache and get the new content from Craft CMS. When a single type is saved the webhook plugins sends a request with the wrong siteId. We have different sites with the same single names.
Steps to reproduce
- Create multiple sites with the same single handel (Home)
- Save the single entry
- Webhook plugins sends a request with another sites id
Saved from default site
Webhook data
GraphQL data
Additional info
- Craft CMS version: 3.7.24
- Webhooks version: 2.4.1
- PHP version: 8.0.15
- Database driver & version: MySQL 5.5.5
- Plugins & versions:
Update: This is not correct. Hiding.
Also running into this issue. I’d imagine this is happening because the webhook is running as a task and the siteId
value isn’t passed in the event parameters.
Possibly an upstream craftcms/cms
issue. Craft’s ModelEvent
might need a $siteId
property so this is carried into the task.
@vlradstake How are you getting the site ID?
@joshuabaker Thanks for answering! This is the payload template:
Do you think entry.getSite().handle
is not working correctly?
{% set entry = event.sender %}
{% set section = entry.getSection() %}
{{
{
time: now|atom,
name: event.name,
entry: {
id: entry.id,
handle: section.handle,
},
site: {
handle: entry.getSite().handle
}
}|json_encode|raw
}}
This is roughly what I was doing too.
The entry.getSite()
call you have will load the site from the database based on the entry.siteId
property on the entry so will match up correctly to whatever that’s set to.
I think what’s happening here is that the webhook task just gets the first entry (i.e. most recent), instead of the one that was saved. Perhaps my above comment is right after all?
@brandonkelly Are you able to provide some steer on this?
I think I have the same issue. I'm getting always the data from the wrong siteId @joshuabaker Did you find a solution or workaround for this problem.
~~Probably I am wrong, but when the fields are related to the entry and the sites are related to the fields, then it's impossible to get the correct site from the entry, because the event is for the entry, which isn't directly related to one site.~~
EDIT: It happened only when the option "Element is being propagated" is enabled.
Hello, having the similar issue when trying to save globals, I have two sites, and {{event.sender.site.baseUrl}}
returns the opposite site (saving globals for site 1, but {{event.sender.site.baseUrl}}
returns 2 and vice-versa).
Here is my webhook configuration:
I have another webhook with similar configuration, the only difference is that the sender class is craft\elements\Entry
, and it works correct.