Bookstack Shelves Update - Given Data is Invalid #2941

Closed
opened 2026-02-05 05:48:48 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @stephencovell on GitHub (Aug 8, 2022).

Describe the Bug

Hello,

I am trying to use the APIs to update shelf books. Unfortunately, I keep getting the following error:

{
    "error": {
        "message": "The given data was invalid.",
        "validation": {
            "tags": [
                "The tags must be an array."
            ]
        },
        "code": 422
    }
}

I'm following the example request given:
https://demo.bookstackapp.com/api/docs#shelves-update

Steps to Reproduce

  1. I've used Postman and Python to test. Python code:
import requests
example_request = {"books": [247]}
auth = "Authorization": "Token token_id:token_secret"
test = requests.post(app_url + '/api/shelves/' + shelve_id, headers=auth, params=example_request)
print(test.text)

Note: The app URL is an example of the request I sent to my Bookstack instance.
2. I've tried the example request sending "[5, 1, 3]" and playing around with the result although I always seem to get the same response,

Expected Behaviour

I expect to see something similar to the example response:
https://demo.bookstackapp.com/api/docs#shelves-update

{
  "id": 14,
  "name": "My updated shelf",
  "slug": "my-updated-shelf",
  "description": "This is my update shelf with some books",
  "created_by": 1,
  "updated_by": 1,
  "owned_by": 1,
  "created_at": "2020-04-10T13:24:09.000000Z",
  "updated_at": "2020-04-10T13:48:22.000000Z"
}

Screenshots or Additional Context

No response

Browser Details

No response

Exact BookStack Version

v22.06.2

PHP Version

No response

Hosting Environment

Ubuntu 22.04, using the Docker script provided:
https://hub.docker.com/r/linuxserver/bookstack

Originally created by @stephencovell on GitHub (Aug 8, 2022). ### Describe the Bug Hello, I am trying to use the APIs to update shelf books. Unfortunately, I keep getting the following error: ``` { "error": { "message": "The given data was invalid.", "validation": { "tags": [ "The tags must be an array." ] }, "code": 422 } } ``` I'm following the example request given: https://demo.bookstackapp.com/api/docs#shelves-update ### Steps to Reproduce 1. I've used Postman and Python to test. Python code: ``` import requests example_request = {"books": [247]} auth = "Authorization": "Token token_id:token_secret" test = requests.post(app_url + '/api/shelves/' + shelve_id, headers=auth, params=example_request) print(test.text) ``` Note: The app URL is an example of the request I sent to my Bookstack instance. 2. I've tried the example request sending "[5, 1, 3]" and playing around with the result although I always seem to get the same response, ### Expected Behaviour I expect to see something similar to the example response: https://demo.bookstackapp.com/api/docs#shelves-update ``` { "id": 14, "name": "My updated shelf", "slug": "my-updated-shelf", "description": "This is my update shelf with some books", "created_by": 1, "updated_by": 1, "owned_by": 1, "created_at": "2020-04-10T13:24:09.000000Z", "updated_at": "2020-04-10T13:48:22.000000Z" } ``` ### Screenshots or Additional Context _No response_ ### Browser Details _No response_ ### Exact BookStack Version v22.06.2 ### PHP Version _No response_ ### Hosting Environment Ubuntu 22.04, using the Docker script provided: https://hub.docker.com/r/linuxserver/bookstack
OVERLORD added the 🐛 Bug label 2026-02-05 05:48:48 +03:00
Author
Owner

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

Hi @stephencovell,
I'm assuming you're getting caught in the validation for a different endpoint here which is confusing matters.
The shelves-update endpoint is a PUT endpoint, your code is performing a POST request currently.

Additionally, if following the API docs examples, you may better off using json=, described in the requests docs here instead of sending data as query params.

To summarize, this line change should apply both of the required changes:

test = requests.put(app_url + '/api/shelves/' + shelve_id, headers=auth, json=example_request)
@ssddanbrown commented on GitHub (Aug 8, 2022): Hi @stephencovell, I'm assuming you're getting caught in the validation for a different endpoint here which is confusing matters. The `shelves-update` endpoint is a `PUT` endpoint, your code is performing a POST request currently. Additionally, if following the API docs examples, you may better off using `json=`, described in the [requests docs here](https://requests.readthedocs.io/en/latest/user/quickstart/#more-complicated-post-requests) instead of sending data as query params. To summarize, this line change should apply both of the required changes: ```python test = requests.put(app_url + '/api/shelves/' + shelve_id, headers=auth, json=example_request) ```
Author
Owner

@stephencovell commented on GitHub (Aug 8, 2022):

Hi,

Thank you for your quick response.

I apologise for putting the POST request, I meant PUT... I copied the wrong code whilst trying to make code for the "snippets to reproduce".

Updating the line works.

Kind Regards,
Stephen Covell

@stephencovell commented on GitHub (Aug 8, 2022): Hi, Thank you for your quick response. I apologise for putting the POST request, I meant PUT... I copied the wrong code whilst trying to make code for the "snippets to reproduce". Updating the line works. Kind Regards, Stephen Covell
Author
Owner

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

Cool! Will therefore close this off.

@ssddanbrown commented on GitHub (Aug 8, 2022): Cool! Will therefore close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2941