# Searching a track with ' in it using the API doesn't work. \[BUG\]

**URL:** <https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695>\
**Category:** Plex Media Server\
**Tags:** server-linux\
**Created:** [April 11, 2021, 12:06pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695 "2021-04-11T12:06:59Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 12:07pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/1 "2021-04-11T12:07:00Z")

</div>

Server Version#: 1.22.2.4282

Very simple. When querying the api, it works fine. But when I’m querying with id=10 (track), `'` break the query. See below:

```auto
#! /bin/bash

# type=2 (series):
GET "http://192.168.2.15:32400/search?query=Agatha Christie's Poirot&type=2&X-Plex-Token=[[API TOKEN]]"
# ' in the name works fine
# above gave valid output with the series. AKA works good

# type=10 (track)
GET "http://192.168.2.15:32400/search?query=I'm upset&type=10&X-Plex-Token=[[API TOKEN]]"
# ' in the name doesn't work
# above didn't find the track that I have (Drake - Scorpion - Disc 1 - Number 6 I'm Upset)
# I am able to view the track using /library, so it's purely because the query didn't work.

# the following also didn't work:
GET "http://192.168.2.15:32400/search?query=I\'m upset&type=10&X-Plex-Token=[[API TOKEN]]"
GET "http://192.168.2.15:32400/search?query=I&#39;m upset&type=10&X-Plex-Token=[[API TOKEN]]" 
    -> 401 Unauthorized
GET "http://192.168.2.15:32400/search?query=I&#8217;m upset&type=10&X-Plex-Token=[[API TOKEN]]"
    -> 401 Unauthorized
```

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 12:43pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/2 "2021-04-11T12:43:09Z")

</div>

> [@Casvt](#):
>
> `http://192.168.2.15:32400/search?query=I'm upset&type=10&X-Plex-Token=[[API TOKEN]]`

This worked fine for me:  
`http://<IP_OF_PMS>:32400/search?query=Sgt.+Pepper’s+Lonely+Hearts+Club+Band&type=10&X-Plex-Token=XXXX`

And do note that I [URL-Encode](https://www.url-encode-decode.com/) the title!  
Note: this was tested with a PMS version=“1.22.2.4282-a97b03fad” on QNAP 64bit x86-64

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 12:59pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/3 "2021-04-11T12:59:07Z")

</div>

> [@Casvt](#):
>
> ```auto
> # type=10 (track)
> GET "http://192.168.2.15:32400/search?query=I'm upset&type=10&X-Plex-Token=[[API TOKEN]]"
> 
> ```

So in your case it should be:

`GET "http://192.168.2.15:32400/search?query=I%27m+upset&type=10&X-Plex-Token=[[API TOKEN]]"`

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 1:26pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/4 "2021-04-11T13:26:48Z")

</div>

> [@dane22](#):
>
> So in your case it should be:
> 
> `GET "http://192.168.2.15:32400/search?query=I%27m+upset&type=10&X-Plex-Token=[[API TOKEN]]"`

I copied that, pasted it into my terminal and put in my api token, but it didn’t work. See below:

```auto
cas@Waveserver:~/scripts$ GET "http://192.168.2.15:32400/search?query=I%27m+Upset&type=10&X-Plex-Token=[[API TOKEN]]"
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="0" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1617650286">
</MediaContainer>

```

* * *

When searching for a series (Agatha Christie’s Poirot), I don’t need to URL-encode the string. It works fine when the string is `Agatha Christie's Poirot`, so why would I need to suddenly URL-encode when I want to search for a track? I don’t have to for series, so why would I need to for tracks? It’s the same system.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 2:13pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/5 "2021-04-11T14:13:31Z")

</div>

> [@Casvt](#):
>
> so why would I need to suddenly URL-encode when I want to search for a track

An url can’t handle a space for one!  
(has to be either `+` or `%20`)

So more puzzeled about why that worked, than I am about the other not working 😉

When said, please provide an [XML Info](https://support.plex.tv/hc/en-us/articles/201998867-Investigate-Media-Information-and-Formats) dump of the track you search for

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 2:16pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/6 "2021-04-11T14:16:06Z")

</div>

> [@Casvt](#):
>
> pasted it into my terminal

What are you using?  
Curl, wget or?

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 2:42pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/7 "2021-04-11T14:42:09Z")

</div>

> [@dane22](#):
>
> So more puzzeled about why that worked,

If you’re talking about the request using `Agatha Christie's Poirot`, it’s (I think atleast) because I quote the request (`"http://..."`).

> [@dane22](#):
>
> An url can’t handle a space for one!

True. But when you quote the request, it works I think. It’s the same in google:

```auto
#When you type this in the google search bar
"https://thetvdb.com/search?query=prison break"
#and press enter, this will be in the searchbar after loading the page.
"https://thetvdb.com/search?query=prison%20break"
#I think it's the same with the requests.
#Spaces are automatically replaced with %20 before processing

```

> [@dane22](#):
>
> What are you using?

`GET`, but it’s the same with `curl` and `wget -O-`

> [@dane22](#):
>
> please provide an [XML Info](https://support.plex.tv/hc/en-us/articles/201998867-Investigate-Media-Information-and-Formats) dump of the track you search for

```auto
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="1" allowSync="1" identifier="com.plexapp.plugins.library" librarySectionID="4" librarySectionTitle="Music" librarySectionUUID="c5610560-7dbd-44a8-8c77-1a258295d911" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1617650286">
<Track ratingKey="8299" key="/library/metadata/8299" parentRatingKey="8293" grandparentRatingKey="8292" guid="plex://track/5d080526403c64029017f274" parentGuid="plex://album/5d07cc4c403c640290e6831a" grandparentGuid="plex://artist/5d07bd1f403c64029059cc32" parentStudio="Cash Money Records" type="track" title="I'm Upset" grandparentKey="/library/metadata/8292" parentKey="/library/metadata/8293" librarySectionTitle="Music" librarySectionID="4" librarySectionKey="/library/sections/4" grandparentTitle="Drake" parentTitle="Scorpion" summary="" index="6" parentIndex="1" ratingCount="231" viewCount="1" lastViewedAt="1613553928" parentYear="2018" thumb="/library/metadata/8293/thumb/1613567016" art="/library/metadata/8292/art/1613567009" parentThumb="/library/metadata/8293/thumb/1613567016" grandparentThumb="/library/metadata/8292/thumb/1613567009" grandparentArt="/library/metadata/8292/art/1613567009" duration="214517" addedAt="1613553346" updatedAt="1614913426">
<Media id="10186" duration="214517" bitrate="320" audioChannels="2" audioCodec="mp3" container="mp3">
<Part id="19349" key="/library/parts/19349/1613553346/file.mp3" duration="214517" file="/home/cas/plex-media/music/Drake/Scorpion/1-06 I'm Upset.mp3" size="8637594" container="mp3" hasThumbnail="1">
<Stream id="45360" streamType="2" selected="1" codec="mp3" index="0" channels="2" bitrate="320" albumGain="-10.37" albumPeak="1.000000" albumRange="11.321794" audioChannelLayout="stereo" gain="-10.37" loudness="-9.80" lra="14.57" peak="1.000000" samplingRate="44100" displayTitle="MP3 (Stereo)" extendedDisplayTitle="MP3 (Stereo)">
</Stream>
</Part>
</Media>
</Track>
</MediaContainer>

```

Searching tracks works fine. But when the track has a `'` in it, it can’t find it.

P.S. I hate drake’s music. It’s horrible. The only reason I have it is because I needed music in the library so that it appears in the api, which I need for an script I’m making that is getting out of hand by now (4444 lines long) but I have nothing to do because school’s still closed 🙁.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 3:09pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/8 "2021-04-11T15:09:57Z")

</div>

I renamed a Beatles song, and ran the following in a browser:

`http://qnap6:32400/search?query=I%27m+upset&type=10&X-Plex-Token=XXXyyyyZZZ`

Output was:

```auto
<MediaContainer size="1" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1617650286">
<Track allowSync="1" librarySectionID="50" librarySectionTitle="Music" librarySectionUUID="84eb5e5e-ad56-4620-9c29-a238b5a09447" parentKey="/library/metadata/4877" personal="1" sourceTitle="QNAP6" ratingKey="4891" key="/library/metadata/4891" parentRatingKey="4877" grandparentRatingKey="4555" guid="plex://track/5d07cdcc403c640290f72440" parentGuid="plex://album/5d07c170403c6402908456cf" grandparentGuid="plex://artist/5d07bbfd403c6402904a674e" parentStudio="EMI" type="track" title="I'm Upset" grandparentKey="/library/metadata/4555" grandparentTitle="The Beatles" parentTitle="1962–1966" originalTitle="The Beatles" summary="" index="1" parentIndex="1" ratingCount="704862" parentYear="1973" thumb="/library/metadata/4877/thumb/1615773572" art="/library/metadata/4555/art/1609589258" parentThumb="/library/metadata/4877/thumb/1615773572" grandparentThumb="/library/metadata/4555/thumb/1609589258" grandparentArt="/library/metadata/4555/art/1609589258" duration="144195" addedAt="1389234366" updatedAt="1615773571">
<Media id="9023" duration="144195" bitrate="128" audioChannels="2" audioCodec="mp3" container="mp3">
<Part id="9053" key="/library/parts/9053/1389234366/file.mp3" duration="144195" file="/share/CACHEDEV1_DATA/audio/The Beatles/The Beatles - 1962-1966 (Red Album)/The Beatles - The Beatles_1962-1966/01 - Love Me Do.mp3" size="2307926" container="mp3"/>
</Media>
</Track>
</MediaContainer>

```

So sadly can’t reproduce here…

Does it also fails in a browser for you?

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 3:20pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/9 "2021-04-11T15:20:17Z")

</div>

When doing the following,  
`http://192.168.2.15:32400/search?query=I%27m+upset&type=10&X-Plex-Token=token`  
inside google, it still can’t find the song.

 ![image](https://global.discourse-cdn.com/plex/original/3X/c/4/c4546ecbc2b76d34f4902d4ad8aa5097b76fa634.png)

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [April 11, 2021, 3:22pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/10 "2021-04-11T15:22:46Z")

</div>

Try and do [the Plex Dance](https://forums.plex.tv/t/the-plex-dance/197064) on it

Edit, and if it still fails, a zip with the logs in debug mode please

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [April 11, 2021, 3:41pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/11 "2021-04-11T15:41:57Z")

</div>

Does it also fail if you simply search inside the web app?

Then it might be your Plex database which is broken.

 ![grafik](https://global.discourse-cdn.com/plex/original/3X/8/a/8ab1036c93019eff05bffc4ac92565f8105911ae.jpeg)

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 3:46pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/12 "2021-04-11T15:46:39Z")

</div>

> [@OttoKerner](#):
>
> Does it also fail if you simply search inside the web app?

Nope:  
 ![image](https://global.discourse-cdn.com/plex/original/3X/7/0/70fa89ab43232e5c1e7a61097f5f3d391f705c83.png)

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [April 11, 2021, 3:49pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/13 "2021-04-11T15:49:35Z")

</div>

Press Enter please, to see more results.  
Which apostrophe are you using? Does the search result change if you copy&paste this into your search field?

```auto
I'm upset

```

But it looks like your server finds actually some items with an apostrophe. So it must be something wrong with your query, I think.  
Maybe you want to listen to the web app when it makes this search query to the server?

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 3:59pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/14 "2021-04-11T15:59:37Z")

</div>

![image](https://global.discourse-cdn.com/plex/original/3X/9/f/9f17cd0d7538eded3b2ca871c26959bb72ea6594.jpeg)  
Typing it myself and copy and pasting the text in your comment gave the same result. Even the url in the search bar is the same after pressing enter.

Scrolling further down, I get lots of results for podcasts, music on tidal etc.

 ![image](https://global.discourse-cdn.com/plex/original/3X/d/e/de66e74a7c0820b38b9d4a39fc63f1f356e39e0b.jpeg)

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [April 11, 2021, 4:02pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/15 "2021-04-11T16:02:56Z")

</div>

Content from Online Media Sources won’t be affected by a damaged server database.  
HOWEVER:

I assume that “Wave” is your server, right? And the sole “track” search result is the right one.  
So the web app does it right and the server database is actually not damaged.

Now you need to find out what the web app is doing differently, to get this correct search result.

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 4:04pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/16 "2021-04-11T16:04:22Z")

</div>

The server name is `Wave server`. It’s indeed a bit stupid of me to think that online sources matter. The track that it found was indeed the right one (in the first screen shot of my previous comment).

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 11, 2021, 4:24pm UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/17 "2021-04-11T16:24:05Z")

</div>

After doing `CTRL+SHIFT+I` and going to `Network` inside google, then searching `I'm Upset` in plex and then stopping the recording on the network page, I got some information.

I’m selecting the second to last request that was made while searching and getting the result:

 ![image](https://global.discourse-cdn.com/plex/original/3X/a/8/a8e7ad1e9678ef596c888b32e54932991061f18e.png)  
Then choosing `Preview` in the window right of it. After clicking some arrows, I found that for `Nummers` (which is dutch for numbers/tracks/songs), it had one result. The key (selected; blue), after I checked using /library in the api in my terminal, is INDEED the key that coresponds to the track!  
 ![image](https://global.discourse-cdn.com/plex/original/3X/b/f/bfb1b91a6a68e4cebb620f30048d0c0ccee1d7d1.png)  
We already knew this because… well we saw that plex found it in the results. But I just wanted to give this information. Maybe I gave you an idea for where I could search. Maybe you now learned how I did it in google and are now able to find something yourself. Maybe I reminded you of something that might help. I don’t know but I thought I’d share.

---

<div class="post-metadata">

**Author:** ![Casvt](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Casvt](https://forums.plex.tv/u/Casvt)\
**Post date:** [April 12, 2021, 9:41am UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/18 "2021-04-12T09:41:03Z")

</div>

I works now after doing the plex dance!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [July 11, 2021, 9:41am UTC](https://forums.plex.tv/t/searching-a-track-with-in-it-using-the-api-doesnt-work-bug/708695/19 "2021-07-11T09:41:28Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
