# Creating Kirby pages via API POST Request

**URL:** <https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566>\
**Category:** Questions\
**Created:** [September 26, 2024, 9:30am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566 "2024-09-26T09:30:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [September 26, 2024, 9:30am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/1 "2024-09-26T09:30:49Z")

</div>

Hi there,

I’m looking to use the Kirby POST API for creating pages. I’m using postman to create a test request, using this endpoint from the Kirby docs

> **[POST /api/pages/:id/children](https://getkirby.com/docs/reference/api/pages/children-create)**
>
> Documentation for the POST /api/pages/:id/childrenAPI endpoint.

My request looks like this, note the url structure -

```auto
const myHeaders = new Headers();
myHeaders.append("Authorization", "••••••");
myHeaders.append("Cookie", "kirby_session=1a2d1f7f76f0adc333e7e92e1776999543008a76%2B1727347035.38c12c1532e7c8a29dae.e2f3741d3c800f33ce7caca7c6c4b59385754b42777985f39c88a479353c8746");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  redirect: "follow"
};

fetch("https://panel.noodsradio.com/api/pages/shows/children/2024/09/george-s-test-show-new", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

```

This is currently responding with a 404. As you can see have a custom folder structure using year and month subfolders to store show entries… is this compatible with the POST endpoint?

Any help on this would be much appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 26, 2024, 9:50am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/2 "2024-09-26T09:50:27Z")

</div>

The URL of your API endpoint doesn’t look right. Should be just

```auto
https://panel.noodsradio.com/api/pages/shows/children

```

If the page is `shows` that you want to add a new child to. You pass the slug for the new page as POST parameter, not in the API endpoint URL.

---

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [September 26, 2024, 10:13am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/3 "2024-09-26T10:13:34Z")

</div>

Thank for the speedy reply @distantnative !

I’ve changed my request as you advised and I’m now able to create a show to the panel.

My request body is as follows

```auto
{
    "slug": "2024+09+george-s-test-show-new",
    "template": "show",
    "content": {
        "title": "A new test show 2025"
    }
}

```

However, this only creates the show in the the root show directory, whereas I would like it be create in a sub folder of shows, in this case /shows/2024/09 i.e this month.

Could you advise how I can achieve this?

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 26, 2024, 1:01pm UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/4 "2024-09-26T13:01:58Z")

</div>

Do the subfolders already exist or would you need to create those children pages first?

---

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [October 7, 2024, 1:55pm UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/5 "2024-10-07T13:55:42Z")

</div>

I got this working by using the following URL structure\*

[https://exampledomain.com/api/pages/shows+2024+09/children](https://exampledomain.com/api/pages/shows+2024+09/children)

\*this is specific to my content folder structure of course

---

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [October 7, 2024, 2:48pm UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/6 "2024-10-07T14:48:08Z")

</div>

Would anyone be able to provide further guidance on how to upload and assign files (images) to pages created in Kirby via the above POST request?

Currently I’m trying the following but I’m unable to determine the structure required for the request body

[https://stagingpanel.noodsradio.com/api/pages/shows+2024+10+george-test-27th-september-24/files](https://stagingpanel.noodsradio.com/api/pages/shows+2024+10+george-test-27th-september-24/files)

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [October 8, 2024, 1:39am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/7 "2024-10-08T01:39:44Z")

</div>

How are you sending the request? From HTML/JavaScript or from PHP?

In general, the files/s need to end up in `$_FILES` and optionally a `template` in the body of the request.

---

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [October 8, 2024, 12:20pm UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/8 "2024-10-08T12:20:02Z")

</div>

I am attempting to send the request via a Javascript fetch request. Am I right to think that the page needs to be created first using a the above POST request, then the image uploaded, and then the page patched / field updated with the image that was uploaded?

If you could provide any guidance on this it would be much appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [October 12, 2024, 11:18am UTC](https://forum.getkirby.com/t/creating-kirby-pages-via-api-post-request/32566/9 "2024-10-12T11:18:25Z")

</div>

Yes that’s correct, those would need to be individual API requests one after the other.

If you are using this in the context of the Panel, you could make use of [https://lab.getkirby.com/public/lab/internals/helpers/upload](https://lab.getkirby.com/public/lab/internals/helpers/upload) for sending the request for the file.
