Strapi API Webhook Trigger without population

System Information
  • Strapi Version: 4.11.1
  • Operating System: Google Cloud Run SaaS
  • Database: PostgreSql
  • Node Version: v18.16.0
  • NPM Version: 9.6.2
  • Yarn Version: -

When making a post/put request to an entity using the Strapi API, the webhook generated does not include the data related to the relation entity. However, when performing the same operation using the UI, the relation data is present in the webhook. You can see the relationpopulates configuration below.

Config File: "…\Cms\Techcareer.StrapiCms\config\server.js"

module.exports = ({ env }) => ({
  //url: env("PUBLIC_URL", "http://localhost:8080"),
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 8080),
  app: {
    keys: env.array('APP_KEYS'),
  },
  webhooks: {
    // Add this to not receive populated relations in webhooks
    populateRelations: true,
  },
});

Sample Request: Location is related entity
Post: {{baseUrl}}/strapicms/api/companies

{
  "data": {
    "name": "Name Test",
    "description": "test desc test desctest desctest desctest desctest desctest desctest desc",
    "logo": "http://www.asd.com",
    "location": 5
  }
}

API Response:
Post: {{baseUrl}}/strapicms/api/companies

{
    "data": {
        "id": 15,
        "attributes": {
            "name": "Name Test",
            "logo": "http://www.asd.com",
            "description": "test desc test desctest desctest desctest desctest desctest desctest desc",
            "createdAt": "2023-06-13T08:09:11.987Z",
            "updatedAt": "2023-06-13T08:09:11.987Z"
        }
    },
    "meta": {}
}

Triggerred Webhook: Location is null
It automatic triggerred from strapi but location value doesnt have.

{
	"event": "entry.create",
	"createdAt": "2023-06-13T08:32:55.708Z",
	"model": "company",
	"uid": "api::company.company",
	"entry": {
		"id": 19,
		"name": "Paşa Test6",
		"logo": "http://www.asd.com",
		"description": "test desc test desctest desctest desctest desctest desctest desctest desc",
		"createdAt": "2023-06-13T08:32:53.249Z",
		"updatedAt": "2023-06-13T08:32:53.249Z"
	}
}

API Populeted Request: It has location entity
Get: {{baseUrl}}/strapicms/api/companies/:id?populate=location

{
    "data": {
        "id": 15,
        "attributes": {
            "name": "Name Test",
            "logo": "http://www.asd.com",
            "description": "test desc test desctest desctest desctest desctest desctest desctest desc",
            "createdAt": "2023-06-13T08:09:11.987Z",
            "updatedAt": "2023-06-13T08:09:11.987Z",
            "location": {
                "data": {
                    "id": 5,
                    "attributes": {
                        "name": "Ağrı / Türkiye",
                        "country": "Türkiye",
                        "city": "Ağrı",
                        "phoneCountryCode": "+90",
                        "createdAt": "2023-03-14T00:00:00.000Z",
                        "updatedAt": "2023-03-14T00:00:00.000Z"
                    }
                }
            }
        }
    },
    "meta": {}
}

Facing the same issue, when using relations, no component will show up in the payload, did you find any solution for this?

Unfortunately i couldn’t.
im hoping for support from the strapi team too.

I opened an issue on Github regarding that, here’s a link if you want to follow up.
Issue

I found solution.

if i have post endpoint with populate query param “blabla/api/jobs?populate=*” then webhook has relation value.
But i use post endpoint without populate query param then webhook has no relation value.

Post Endpoint For Relation Value: {{baseUrl}}/strapicms/api/jobs?populate=*
Post Endpoint For No Relation Value: {{baseUrl}}/strapicms/api/jobs

1 Like

What if I don’t use any api endpoint? I’m just using webhooks to dump the results on Azure, and there’re no endpoints in my code.

This solution didn’t work out for me, I don’t create using API.

I use the CMS for creating relations, then on publishing, I trigger a webhook to return all values to another service that process the data.

Hi,
I think you’re using the website interface.
For this, it will be enough to set the config file I mentioned above.

Tried it, didn’t work.

@pasayazici Thank you for the information. We have the following case, which is related to this behaviour and the question from @Emad_Eibo : We are creating entries via GraphQL. A Webhook is triggered by the “entry.create” event and pushs the model into another system, but the Webhook payload doesn’t contain the relation components. As explained here, it is possible to write a custom middleware to populate all fields and relations via the api. However, this doesn’t seem to impact the webhook triggered by GraphQL mutations. Is there any way to populate all fields and relations in the Webhook when the entry is created by a GraphQL mutation?

@JWandscheer
I found a workaround solution to this problem.
You can find the solution in my answer above.

@pasayazici this works for REST API requests but not for GraphQL, right?
I need to get a webhook with all relations triggered by creation of a new entry via GraphQL.

Hello,

I use strapi version below:
@strapi/strapi”: “4.19.0”,

and

config/server.ts

and works for me