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.

REST API create object with upload field

default discord avatar
titobandito1358last year

Hi, I'm trying to create a new object in a collection containing an upload field.



The collection has approximately the following model:



submissions {
  message: text,
  attachments: upload
}


In order to create a new object with attachments, I do the following:



I create all the uploads first using the REST interface and I save the resultant

doc.id

s in a list.



I then make a create (POST) request to the collection endpoint with the following JSON body:



{
  message: string,
  attachments: string[] // These are the doc.id's 
}


The issue I'm having is that every time I try to pass the list of ids, I get the following error:



{"errors":[{"name":"ValidationError","message":"The following field is invalid: attachments","data":[{"message":"This field is not a valid upload ID.","field":"attachments"}]}]}


When I manually check the ids, I see that they are in fact the right ideas for object within the uploads collection.



What am I doing wrong?



I figured it out! Sorry for clogging up the forum! I forgot to put the upload field in an array field. To actually push I mapped the ids to

{ attachment: id }

and now everything works fine!

    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.