API - Optimize Database

Hello -
I have a script that backs up the PMS folders, and I wanted to modify the script to optimize the db before I back it up.

I can run the following:
curl -X POST http://127.0.0.1:32400/butler/OptimizeDatabase?X-Plex-Token=

However, I thought it might make more sense (maybe it doesn’t?) to run one that isn’t based on Scheduled Tasks, so I tried:
curl -X POST http://127.0.0.1:32400/library/optimize?async=0?X-Plex-Token=

With the 2nd option, I get a “401 Unauthorized” error.

I am using the same Plex Token for both commands…

What am I doing wrong?

It’s async=1

Hi, dane22 -
Thank you for the tip - but, I have tried async=0 and async=1 and the result is the same.

Heh, I forgot one thing as well…

The method is PUT and not POST

Just tried:

curl -X PUT http://127.0.0.1:32400/library/optimize?async=1?X-Plex-Token=

And the result was the same.

And you did have a client identifier as a param as well?

/library/optimize?async=1&X-Plex-Client-Identifier=SoMeRaNdOmStRiNg&X-Plex-Token=XXXXXXXX

Try it like this:

curl -X PUT -H "X-Plex-Token: your_token" http://127.0.0.1:32400/library/optimize?async=1

This is what worked for me.

And lastly a small hint…

When digesting endpoints, use the webclient and check the network tab of the debugger in the browser

I ended up using pshanew’s suggestion, and it works

Thanks dane22 and pshanew!

You had two ? in your query parameters.

Yeah, that was just the latest iteration… I had tried several variations, so I knew I was messing up somewhere. pshanew’s post educated me on the -H option to pass multiple headers in curl. Also, now I have learned about URL query strings!

Lastly, I am using async=0, because the script pauses until the optimizing is done, which I prefer over async=1 which allows the script to continue immediately. Is there any reason I shouldn’t use async=0?