Update Shelf via API doesn't work to me #1734

Closed
opened 2026-02-05 01:44:05 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @kritschy on GitHub (May 14, 2020).

First of all, I want to apologize. I'm not a php pro and probably for this reason the code is quite messy and confusing.

Describe the bug
Though I get a 200 back my changes to a shelf don't appear.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Execute the following code: https://gist.github.com/TheVeggie/9e33d06c5005769768e2bd9c89b69666

  2. See error

Expected behavior
Imo the code should create a book and immediately put it to the given shelf.

Screenshots
If applicable, add screenshots to help explain your problem.

Your Configuration (please complete the following information):

  • Exact BookStack Version (Found in settings): v0.29.2
  • PHP Version: 7.4.6
  • Hosting Method (Nginx/Apache/Docker): php cli server

Additional context
Add any other context about the problem here.

Originally created by @kritschy on GitHub (May 14, 2020). First of all, I want to apologize. I'm not a php pro and probably for this reason the code is quite messy and confusing. **Describe the bug** Though I get a 200 back my changes to a shelf don't appear. **Steps To Reproduce** Steps to reproduce the behavior: 1. Execute the following code: https://gist.github.com/TheVeggie/9e33d06c5005769768e2bd9c89b69666 2. See error **Expected behavior** Imo the code should create a book and immediately put it to the given shelf. **Screenshots** If applicable, add screenshots to help explain your problem. **Your Configuration (please complete the following information):** - Exact BookStack Version (Found in settings): v0.29.2 - PHP Version: 7.4.6 - Hosting Method (Nginx/Apache/Docker): php cli server **Additional context** Add any other context about the problem here.
Author
Owner

@ssddanbrown commented on GitHub (May 15, 2020):

Hi @TheVeggie,

I think some of the code to debug the curl responses was incorrect, causing you to maybe be misled. There were no $decoded->response->status properties leading to the error catching logic not running.

I forked your gist and made some updates here:
https://gist.github.com/ssddanbrown/c74c84e89e5bf53395abba27d1bd7ef5
This script worked during my testing. I've added comments at each stage so the logic can be followed.
I've also added logic to fetch the shelf before updating, so the existing book ids can be considered otherwise they'd be removed.

Note, I removed your $_POST[] usages and hard-coded these details since I was testing via command line but I've left them as comments in the areas they'd be used.

Let me know if you have any other issues, need further help or if you want me to explain any parts in my code.

@ssddanbrown commented on GitHub (May 15, 2020): Hi @TheVeggie, I think some of the code to debug the curl responses was incorrect, causing you to maybe be misled. There were no `$decoded->response->status` properties leading to the error catching logic not running. I forked your gist and made some updates here: https://gist.github.com/ssddanbrown/c74c84e89e5bf53395abba27d1bd7ef5 This script worked during my testing. I've added comments at each stage so the logic can be followed. I've also added logic to fetch the shelf before updating, so the existing book ids can be considered otherwise they'd be removed. Note, I removed your `$_POST[]` usages and hard-coded these details since I was testing via command line but I've left them as comments in the areas they'd be used. Let me know if you have any other issues, need further help or if you want me to explain any parts in my code.
Author
Owner

@kritschy commented on GitHub (May 17, 2020):

thank you! works fine and and is understandable to me :)

@kritschy commented on GitHub (May 17, 2020): thank you! works fine and and is understandable to me :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1734