Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Additional added fields in Media object API are not returned

default discord avatar
loaialshareelast year
3

Hi! I am having a collection that has an upload field. When I use the API endpoint to get the collection data including the media object related, I only receive the media object with the following fields by default:

id

,

filename

,

mimeType

,

filesize

,

width

,

height

,

url

. However, all additionally added fields using

beforeChange

hook in media collection are not returned even though they are successfully stored in media db. Is there anything I need to enable/configure to be able to return them as well?

  • default discord avatar
    imcorfitzlast year

    How does the object in MongoDB look?

  • default discord avatar
    loaialshareelast year
    @591695886720172033

    It looks like this:



    _id: ObjectId('id')
    external_url: "test"
    filename: "test-18.png"
    mimeType: "image/png"
    filesize: 4369
    width: 248
    height: 71
    __v: 0

    I need to get the

    external_url

    field to be part of the returned API.



    Update: When I put the endpoint within the collection itself, that field appears, but when I put the endpoint in

    payload.config.ts

    , the field disappears. That is even more confusing because I intent to place the endpoint within

    payload.config.ts

    not within the collection



    Update2: It seems that my issue was that I have set the field directly to

    hidden: true

    thinking that it will disable the field from appearing on the UI, while the reality is that it was actually hiding the field from appearing in the API.


    {
          name: 'external_url',
          type: 'text',
          hidden: true
    }

    The correct implementation for hiding the field from admin UI is that it should be wrapped with admin config like this:


    {
          name: 'external_url',
          type: 'text',
          admin: {
            hidden: true,
          },
    }

    This would hide it from admin UI but keep it in the API. Thankss!!

  • default discord avatar
    imcorfitzlast year

    🚀

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.