REST API create object with upload field

default discord avatar
titobandito1358
3 weeks ago

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!

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

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

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