API Ability - Create gallery-image of type "cover_book" #5256

Closed
opened 2026-02-05 09:51:55 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @MaximeLibert on GitHub (Apr 15, 2025).

API Endpoint or Feature

Using the existing create method for image-gallery , people should be able to use type "cover_book" to create a book cover to then link to a book.

Use-Case

I am currently developing a small python connector that creates books in my BookStack instance, I would like to be able to add book covers using the API endpoint.

My planned method was, using API:

  1. Creating the book - POST call with book infos (content type = json)
  2. Creating the image gallery of type "cover_book" - POST call with image (content type = multipart/form-data)
  3. Updating the book with image field - PUT call with image (content type = multipart/form-data)

As you probably know, I cannot use type "gallery" cause it would interpret the uploaded_to value to be a page id not a book id.

Additional context

No response

Originally created by @MaximeLibert on GitHub (Apr 15, 2025). ### API Endpoint or Feature Using the existing create method for image-gallery , people should be able to use type "cover_book" to create a book cover to then link to a book. ### Use-Case I am currently developing a small python connector that creates books in my BookStack instance, I would like to be able to add book covers using the API endpoint. My planned method was, using API: 1. Creating the book - POST call with book infos (content type = json) 2. Creating the image gallery of type "cover_book" - POST call with image (content type = multipart/form-data) 3. Updating the book with image field - PUT call with image (content type = multipart/form-data) As you probably know, I cannot use type "gallery" cause it would interpret the uploaded_to value to be a page id not a book id. ### Additional context _No response_
OVERLORD added the 🔩 API Request label 2026-02-05 09:51:55 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Apr 15, 2025):

Hi @MaximeLibert,

Both the books - POST - Create and books - PUT - Update endpoints directly accept image data via the image parameter as part of a multipart/form-data form data request.
You don't need to upload them via a separate endpoint and then "attach" them (your planned steps 2 & 3). You can just provide the image during the creation (Step 1).

@ssddanbrown commented on GitHub (Apr 15, 2025): Hi @MaximeLibert, Both the `books - POST - Create` and `books - PUT - Update` endpoints directly accept image data via the `image` parameter as part of a `multipart/form-data` form data request. You don't need to upload them via a separate endpoint and then "attach" them (your planned steps 2 & 3). You can just provide the image during the creation (Step 1).
Author
Owner

@MaximeLibert commented on GitHub (Apr 15, 2025):

Hi @ssddanbrown ,

Sorry, I was lazy in my context explanation.

The python connector that I am currently building will be used to sync content from one BookStack instance to another. Both are in different networks so I cannot implement the content of multi-instance or "just" use permission to have some users see only some parts of one instance cause they wont be able to access it.

For that, I have decided to use API calls and not webhooks cause it is easier for me to trigger the rebuild of the source instance and so on.

I plan to have my technical API user to only be able to read some parts of the source instance (based on shelves rights) and just upsert the content in the other instance. Thus, I will check periodically what was "last updated" and store id mappings in a database. My script is almost finished, everything works except book covers.

For every "attachments" and "images" of source instance my logic is:
Creating the image gallery or attachment" - POST call with file (content type = multipart/form-data) OR Updating the attachment/image if already in destination
Updating the page with file- PUT call with file(content type = multipart/form-data) (even if it might be useless some of the times)
Updating the content of the page to change the hrefs.

I wanted to reuse this logic in order not to rewrite code for the book covers since they are "just" specific image galeries with type "book_cover" but the API wont allow me to do so. I could do what you proposed so thanks in advance for this.

@MaximeLibert commented on GitHub (Apr 15, 2025): Hi @ssddanbrown , Sorry, I was lazy in my context explanation. The python connector that I am currently building will be used to sync content from one BookStack instance to another. Both are in different networks so I cannot implement the content of [multi-instance](https://www.bookstackapp.com/docs/admin/multi-instance/) or "just" use permission to have some users see only some parts of one instance cause they wont be able to access it. For that, I have decided to use API calls and not webhooks cause it is easier for me to trigger the rebuild of the source instance and so on. I plan to have my technical API user to only be able to read some parts of the source instance (based on shelves rights) and just **_upsert_** the content in the other instance. Thus, I will check periodically what was "last updated" and store id mappings in a database. My script is almost finished, everything works except book covers. For every "attachments" and "images" of source instance my logic is: Creating the image gallery or attachment" - POST call with file (content type = multipart/form-data) OR Updating the attachment/image if already in destination Updating the page with file- PUT call with file(content type = multipart/form-data) (even if it might be useless some of the times) Updating the content of the page to change the hrefs. I wanted to reuse this logic in order not to rewrite code for the book covers since they are "just" specific image galeries with type "book_cover" but the API wont allow me to do so. I could do what you proposed so thanks in advance for this.
Author
Owner

@MaximeLibert commented on GitHub (Apr 15, 2025):

Feedback after trying your solution

Image

Do I need to set something up for this to work ??

@MaximeLibert commented on GitHub (Apr 15, 2025): Feedback after trying your solution ![Image](https://github.com/user-attachments/assets/480c8d6e-9e52-4081-8402-4396184f3eac) Do I need to set something up for this to work ??
Author
Owner

@ssddanbrown commented on GitHub (Apr 15, 2025):

@MaximeLibert For a PUT request you'll need to add a _method form item with value PUT as an awkward workaround to a PHP limitation (hopefully to be solved soon). Is mentioned in the API docs but easy to miss. POST requests are fine.

@ssddanbrown commented on GitHub (Apr 15, 2025): @MaximeLibert For a PUT request you'll need to add a `_method` form item with value `PUT` as an awkward workaround to a PHP limitation (hopefully to be solved soon). Is mentioned in the API docs but easy to miss. `POST` requests are fine.
Author
Owner

@MaximeLibert commented on GitHub (Apr 16, 2025):

Thanks for this, its true that it is easy to miss !

Thank you for your for your time man !

@MaximeLibert commented on GitHub (Apr 16, 2025): Thanks for this, its true that it is easy to miss ! Thank you for your for your time man !
Author
Owner

@ssddanbrown commented on GitHub (Apr 16, 2025):

No worries!

I'm going to go ahead and close this request as out of scope though.
The gallery image endpoints are specifically intended for content images, with other endpoints used for other images, and I'm not keen on duplicating actions across endpoints.

@ssddanbrown commented on GitHub (Apr 16, 2025): No worries! I'm going to go ahead and close this request as out of scope though. The gallery image endpoints are specifically intended for content images, with other endpoints used for other images, and I'm not keen on duplicating actions across endpoints.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5256