# Insert a json with multiple elements

**URL:** <https://discourse.getcockpit.com/t/insert-a-json-with-multiple-elements/3075>\
**Category:** Support\
**Created:** [October 29, 2024, 1:33pm UTC](https://discourse.getcockpit.com/t/insert-a-json-with-multiple-elements/3075 "2024-10-29T13:33:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Sebastian](https://discourse.getcockpit.com/u/Sebastian)\
**Post date:** [October 29, 2024, 1:33pm UTC](https://discourse.getcockpit.com/t/insert-a-json-with-multiple-elements/3075/1 "2024-10-29T13:33:00Z")

</div>

I would like to know how I could insert a json with multiple elements.

It seems that from the documentation I can only insert 1 article at a time:

```auto
fetch('https://cockpit.tld/api/content/item/posts', {
method: 'POST',
headers: {
"api-key": "a2ea86ea065a6d2301a8b4a535bc",
"Content-Type": "application/json"
},
body: JSON.stringify({
data: { item1, item2, itemN }
})
})
.then(response => response.json())
.then(response => console.log(response));

```

---

<div class="post-metadata">

**Author:** ![Sebastian](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Sebastian](https://discourse.getcockpit.com/u/Sebastian)\
**Post date:** [November 2, 2024, 11:18am UTC](https://discourse.getcockpit.com/t/insert-a-json-with-multiple-elements/3075/3 "2024-11-02T11:18:18Z")

</div>

To insert more elements I had to do a loop.  
Example:

```auto
bookings.forEach(async (booking) => {
    try {
      const response = await fetch(
        `${process.env.HOST}/api/content/item/bookings`,
        {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ data: booking }),
        }
      );

      if (!response.ok) {
        throw new Error(`HTTP error! Status: ${response.status}`);
      }

      const result = await response.json();
      console.log("booking :", result);
    } catch (error) {
      console.error("Error:", error);
    }
  });

```
