Post with nested relations

Hey guys… is it possible to POST to /orders and set order-bucket(s) as nested relations?

I want to create an order what can have multiple buckets of cameras & lenses for different date-ranges

This topic has been created from a Discord post (1222249382720573503) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

<@960590891200970812> or <@211722558385553408> :wave: maybe you guys got a second and check my idea if it’s even possible :slightly_smiling_face:

Thanks for open :studio_microphone: discussion :slightly_smiling_face: I’m on it!

Discussed in office hours but TLDR best to use Nuxt server actions :heart:

<@211722558385553408> hey… if you have a minute can we chat a bit? :slightly_smiling_face: I’m back on that project and actually executing what we were talking about

I got the logic working… doing the requests on nuxt level in a chain, but for some weird reasons I can’t fill order_buckets with an array afterwards… it just doesn’t go threw… I’ve been trying to solve it, but no success

orderBucketData {
  data: {
    fromDate: '2024-04-21',
    toDate: '2024-04-25',
    cameras: [ 3, 1 ],
    lenses: [ 33, 18 ]
  }
}
bucketIds [ 38 ]
orderData { data: { email: 'lamp@email.ee', order_buckets: [ 38 ] } }
orderResponseData {
  data: {
    id: 30,
    attributes: {
      email: 'lamp@email.ee',
      createdAt: '2024-04-18T13:47:34.225Z',
      updatedAt: '2024-04-18T13:47:34.225Z',
      publishedAt: '2024-04-18T13:47:34.224Z'
    }
  },
  meta: {}
}

I added delay between the calls… but that didn’t help either… just for testing purposes

I can manually add the relation in Strapi dropdown so the relations are correctly set imho

but for some reasons it doesn’t set it via the API call

Does the user have the find permission on that related content-type?

ahaa… good point… didn’t know that it needs to find when inserting thought it’s only for fetching

yeah it’s a bit obscure that the user needs access to that content-type to set relations, do be careful though as enabling that permission will grant them access to the find-all endpoint, you may want to create a route policy/middleware for that route if you don’t want them to use it.

it’s fine as this request is done on backend side and token is not public

got it working now… thanks!