API update page not working #2963

Closed
opened 2026-02-05 05:52:08 +03:00 by OVERLORD · 5 comments
Owner

Originally created by @JtheBAB on GitHub (Aug 15, 2022).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

I am playing around with the API System and try to update a page.

I send the following body:

{"id":1982,"book_id":37,"chapter_id":0,"name":"test","html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong> - Update<\/p>"}

by using

Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body

I get

StatusCode : 200 StatusDescription : OK Content : {"id":1982,"book_id":37,"chapter_id":0,"name":"test","slug":"test","html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong><\/p>","priority":11,"created_at":"2022-08-15T13:25:53.000...

and see on the corresponding bookstack page that the Revision counter goes up and the "Updated ..." changes. But the text stays at the old version and also when i click on the Revision link i just see the real changes and not all my tests.

Any idea why the page isn't updated?

Exact BookStack Version

v22.07.3

Log Content

PHP Version

7.4

Hosting Environment

Debian 11

Originally created by @JtheBAB on GitHub (Aug 15, 2022). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario I am playing around with the API System and try to update a page. I send the following body: `{"id":1982,"book_id":37,"chapter_id":0,"name":"test","html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong> - Update<\/p>"}` by using `Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body` I get `StatusCode : 200 StatusDescription : OK Content : {"id":1982,"book_id":37,"chapter_id":0,"name":"test","slug":"test","html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong><\/p>","priority":11,"created_at":"2022-08-15T13:25:53.000... ` and see on the corresponding bookstack page that the Revision counter goes up and the "Updated ..." changes. But the text stays at the old version and also when i click on the Revision link i just see the real changes and not all my tests. Any idea why the page isn't updated? ### Exact BookStack Version v22.07.3 ### Log Content - ### PHP Version 7.4 ### Hosting Environment Debian 11
OVERLORD added the 🐕 Support📖 Docs Update labels 2026-02-05 05:52:08 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Aug 15, 2022):

Hi @JtheBAB,

  • Is the HTML content being sent different to what already exists?
  • Are making this request with a Content-Type header?
@ssddanbrown commented on GitHub (Aug 15, 2022): Hi @JtheBAB, - Is the HTML content being sent different to what already exists? - Are making this request with a `Content-Type` header?
Author
Owner

@JtheBAB commented on GitHub (Aug 15, 2022):

Hi @ssddanbrown

Is the HTML content being sent different to what already exists?

Yes.

Original:

"html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong><\/p>"

New:

"html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong> - Update<\/p>"

Basically the same as in the API documentation. But also when i replace it to

"html":"Bla bla"

the page doesn't change.

Are making this request with a Content-Type header?

I guess so as i sent now (above it is missed).

$contentType = "application/x-www-form-urlencoded"
Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body -ContentType $contentType

@JtheBAB commented on GitHub (Aug 15, 2022): Hi @ssddanbrown >Is the HTML content being sent different to what already exists? Yes. Original: `"html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong><\/p>"` New: `"html":"<p id=\"bkmrk-das-ist-ein-test\">Das ist ein <strong>Test<\/strong> - Update<\/p>"` Basically the same as in the API documentation. But also when i replace it to `"html":"Bla bla"` the page doesn't change. >Are making this request with a Content-Type header? I guess so as i sent now (above it is missed). `$contentType = "application/x-www-form-urlencoded"` `Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body -ContentType $contentType`
Author
Owner

@ssddanbrown commented on GitHub (Aug 16, 2022):

Hi @JtheBAB,

If you are sending JSON content like in your original example above your request content type will need to match, and therefore be application/json

@ssddanbrown commented on GitHub (Aug 16, 2022): Hi @JtheBAB, If you are sending JSON content like in your original example above your request content type will need to match, and therefore be `application/json`
Author
Owner

@JtheBAB commented on GitHub (Aug 16, 2022):

Hi @ssddanbrown

Thank you. Then i complete misunderstand the docs in the "Request Format" section. Now it works with:

$contentType = "application/json" Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body -ContentType $contentType

with

{"id":1982,"book_id":37,"name":"test","html":"Bla bla"}

as payload.

As a side note:

When i do a GET on that page, Bookstack delivers with "chapter":0. But when i send it with "chapter":0 i get

{"error":{"message":"No query results for model [BookStack\\Entities\\Models\\Chapter] 0","code":404}}

Thank you again :)

@JtheBAB commented on GitHub (Aug 16, 2022): Hi @ssddanbrown Thank you. Then i complete misunderstand the docs in the "Request Format" section. Now it works with: `$contentType = "application/json" Invoke-WebRequest -uri https://url/api/pages/1982 -Headers $Headers -method PUT -Body $body -ContentType $contentType` with `{"id":1982,"book_id":37,"name":"test","html":"Bla bla"}` as payload. As a side note: When i do a GET on that page, Bookstack delivers with "chapter":0. But when i send it with "chapter":0 i get `{"error":{"message":"No query results for model [BookStack\\Entities\\Models\\Chapter] 0","code":404}}` Thank you again :)
Author
Owner

@ssddanbrown commented on GitHub (Aug 23, 2022):

Within 760eff397f I have now updated the "Request Format" section to clarify things to help avoid confusion in future. I will therefore close this off.

In regards to the chapter id, yeah, there is some misalignment currently for requests/responses, since BookStack internally uses 0 to denote lack of relation but the API expects null from users.

@ssddanbrown commented on GitHub (Aug 23, 2022): Within 760eff397f51e1bb616202dc6a8561ea52bac3a8 I have now updated the "Request Format" section to clarify things to help avoid confusion in future. I will therefore close this off. In regards to the chapter id, yeah, there is some misalignment currently for requests/responses, since BookStack internally uses `0` to denote lack of relation but the API expects `null` from users.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2963