Make a post request to strapi and add data to a component

I am building an online community with strapi and React.

I am really stuck and seeking for answer .

I created a collection type called blog that has 4 fields

name, email, id, comments.

comments has value a repeatable component that has 4 fields

name, id , img, comment.

below is the datastructure

{

“blogs” : "[

{

“name”: “gabriel”,

“_id”: “1”,

“email”: "[myemail]

“comments”: [

{

"name ": “strapi”,

“id” :1,

"img ": “user1Image”,

“comment”:“I love this blog”

},

{

"name ": “node”,

“id” :2,

"img ": “user2Image”,

“comment”:“I want to eat”

},

],

},

]"

}

I could add data into a comments field manually since its value is a repeatable component , however, how can I make request to allow users to post data on the comments fields above.

I looked strapi docs and it seems like component doesn’t have an endpoint.

I am really stuck please.

any resources that could guide me throughout the solution will be really appreciate

here was my first approache

axios

.post(“http://localhost:1337/blogs/”, {

comments: {

name:“gabriel”,

id :“3”,

“img”:“user3image”,

comment:“strapi is amazing”

}

})

.then((response) => {

console.log(“User profile”, response.data);

})

.catch((error) => {

console.log(“An error occurred:”, error.response);

});

I also address the issue on github and stackoverflow.

seem like strapi docs is missing things or they might have not thought about building that feature

1 Like

Even I am wondering the same. @DMehaffy can you help on this?

Hi @Gabriel-Andy
You can post data to components as a json inside json only,

         "data":{
             "component": {
                   field1: value1,
                   field2: value2
             }
}