'strapi v4: How to create a Entry with Relation?
When I create a new entry in my Collection-Type all of the values for the fields get added to the newly created entry EXCEPT for the value for the field with the Relation type.
So for example in my event Collection-Type I have name, performers, venue, address, date, time, description and user
user is a Relation type (Relation with User (from:users-permission))
The rest are either Text, DateTime, RichText, etc.
after I get the data from the form I end up having a object similar to:
var values = {
name: 'namevalue',
performers: 'whatever',
venue: 'whatever',
address: 'xyz address',
date: '2022-12-15',
time: '10:00 PM',
description: 'Description of the Event',
}
I then just edit the values object above to get the final version of value as
var values = {
name: 'namevalue',
performers: 'whatever',
venue: 'whatever',
address: 'xyz address',
date: '2022-12-15',
time: '10:00 PM',
description: 'Description of the Event',
user:1
}
PLEASE TAKE NOTE OF the user:1 added to the object above
However after submitting the above values to the correct endpoint:
const res = await fetch(`${API_URL}/api/events`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
data: values,
}),
})
In the Strapi backend the user field and value totally does not show up.... For example this is what I get:
{
data: {
name: '13',
performers: '13',
venue: '13',
address: '13',
date: '2022-06-10',
time: '8:00 PM',
description: '13'
},
files: undefined
}
As you can see the rest of the data I get and it then gets added to the newly created Entry but WITHOUT the Relation value that I need and want.
What am I doing wrong and how to fix this????
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
