How to use API endpoint for creating pages

Hey,

I am currently trying to create a page for a translated page item and I have a weird error I dont understand.
currently I am using Postman and have the following setup:

Url: https://kirby-test.jr.local/api/pages/blog/children
Type: POST
Headers: x-language: en
Body as form-data/x-www-form-encoded:

slug:windows-server-2016-startmenue-oeffnet-nicht
    title:Windows Server 2016+ - Startmenü öffnet nicht
    content:{ "overview": "test"}

If I send this request I get the following error:
{
“status”: “error”,
“message”: “Cannot access offset of type string on string”,
“code”: 500,
“exception”: “TypeError”,
“key”: null,
“file”: “…/kirby-test/kirby-test-inst-1/kirby/src/Cms/PageActions.php”,
“line”: 484,
“details”: ,
“route”: “pages/([a-zA-Z0-9\.\-_%= \+\@\(\)]+)/children”
}

I pass the data as described in the documentation - content as json array, the slug is from an already created page, so I can use the x-lang header to create the second file and the title is also from an already created page - both of these data are from the kirby API so I would guess the format should be correct (to find the correct page item). I also tried to pass the content as array of json objects but I get the same error^^

Thank you for help :slight_smile:

I think that is a misunderstanding, you are using the wrong endpoint.

What you want to do is to update an existing page, not create a new one.

So the correct API endpoint would be: <code>PATCH</code> /api/pages/:id | Kirby CMS

Also, the data should be sent as JSON, not as form data

1 Like

Hey :slight_smile:

as always, thank you for your great help. I tried to use your endpoint but I can’t access the right folder… - If I use your endpoint I modify the Blog page (for reference my setup from content root folder: content > 1_blog (folder) > date_article_title (folder) (e.g 20230117_mqtt-ein-ueberblick) > article.de.txt)

If I use your suggested endpoint I will modify the article.de.txt in the folder “1_blog” - But I want to modify the children (e.g. the article.en.txt in folder “1_blog/20230117_mqtt-ein-ueberblick”) or with a bit more information as example my desired workflow:

The folder I want to work in is the following:
Path: content/1_blog/20230117_mqtt-ein-ueberblick => This folder contains the following files:

article.de.txt
*.pictures

With the Kirby API endpoint https://kirby-test.jr.local/api/pages/blog/children?limit=1&select=id, title, content, status,slug&page=1 I fetch this page including all needed information.

After I have done my stuff, I want now to create the article.en.txt file in this folder (not in the 1_blog folder but in the “20230117_mqtt-ein-ueberblick” folder.)

If I use the ID given by the kirby API from fetching this site I get 404 with my patch request
No route found for path: \"pages/blog/mqtt-ein-ueberblick\" and request method: \"PATCH\""
same thing if I use the slug I get the following error "The page \"mqtt-ein-ueberblick\" cannot be found", → This folder does not exist so I understand why this is not working.

Editing my body as RAW Json works, thanks for that :slight_smile:

You need to use a + for the id, not a slash

\"pages/blog+mqtt-ein-ueberblick\

id is always the complete path to a page, not just the slug.

1 Like