Adding custom data in the API response

default discord avatar
last month

Hello Question - I'm not really sure where to look. May someone point me in the right direction to find relevant docs?

I have a field

    name: 'location',
    type: 'text',
    label: "Location",
    required: true,

And of course with the field filled out shows up as this in the API

"location": "London",

For some basic example lets say I want to return a value but is not something seen or edited in the collection for this. Is hooks where I should go? I want the result to look like such:

"location": "London",
  "customHiddenStuff": "Foo",
  "customHiddenNumber": "123",

Where might I find docs relevant to this? Thank you

  • default discord avatar
    last month

    Zushi - ive used the afterRead hook for things like this. In my case i was removing some data - but no reason it couldnt also be used to add data

  • default discord avatar
    last month

    is perfect for transforming data that does not need to be saved.

    I'm not sure if you can add data that is not part of the schema, however.

  • default discord avatar
    last month

    Thank you!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.