The Movie Database Support

I'm using the javascript library.

There's no way to remove a movie from that list:

Passing the movie_watchlist = false doesn't work.

It returns always a 201 code (success) and the movie is not removed. (Even though In the api doc, there is 200 as a successful response).

I've tried several methods, passing the parameter as query or in the body, but no way.

The example the api doc provides doesn't work, returning some errors about cross-domain issues.

Here is the request

Request URL:http://api.themoviedb.org/3/account/xxxx/movie_watchlist?api_key=xxxx
Request Method:POST
Status Code:201 Created

Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:it,en-US;q=0.8,en;q=0.6,ja;q=0.4,fr;q=0.2,it-IT;q=0.2,zh-CN;q=0.2,zh;q=0.2
Connection:keep-alive
Content-Length:89
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:api.themoviedb.org
Origin:http://localhost:8888
Referer:http://localhost:8888/xxx
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36

Query String Parameters
api_key:xxx
Form Dataview 
session_id:xxx
movie_id:251519
movie_watchlist:false

Even if it is not strictly as indicated in the api doc, it works in adding, but fails in removing.

Thanks Andrea

P.S.: thanks for your GREAT work!

11 replies (on page 1 of 1)

Jump to last post

Hi Andrea,

I'm out of the office tomorrow but will look into this on Thursday. Thanks.

Hi Andrea,

I can't quite seem to replicate this. These 4 calls add and remove the items properly for me:

curl  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d "{'movie_id': 550, 'favorite': true}" "http://api.themoviedb.org/3/account/{ID}/favorite?api_key=###&session_id=###"

curl  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d "{'movie_id': 550, 'favorite': false}" "http://api.themoviedb.org/3/account/{ID}/favorite?api_key=###&session_id=###"

curl  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d "{'movie_id': 550, 'movie_watchlist': true}" "http://api.themoviedb.org/3/account/{ID}/movie_watchlist?api_key=###&session_id=###"

curl  -H "Accept: application/json" -H "Content-Type: application/json" \
  -d "{'movie_id': 550, 'movie_watchlist': false}" "http://api.themoviedb.org/3/account/{ID}/movie_watchlist?api_key=###&session_id=###"

Are you posting the JSON as a body data?

Hi Travis,

thank you. Yes I've tried several ways but I can't make it.

here is the javascprit code (exactly copied from the doc):

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "http://api.themoviedb.org/3/account/"+id+"/favorite?api_key="+theMovieDb.common.api_key+"&session_id="+session_id);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Accept", "application/json");
    xhr.onreadystatechange = function () {
      if (this.readyState == 4) {
        alert('Status: '+this.status+'\nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'\nBody: '+this.responseText);
      }
    };
    xhr.send("{'movie_id': 8765, 'favorite': false}");

Here the network log from Chrome:

Remote Address:23.21.44.221:80
Request URL:http://api.themoviedb.org/3/account/xxx/favorite?api_key=xxx&session_id=xxx
Request Method:OPTIONS
Status Code:404 Not Found
Request Headers
OPTIONS /3/account/6131604/favorite?api_key=xxx&session_id=xxx HTTP/1.1
Host: api.themoviedb.org
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:8888
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: http://localhost:8888/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: it,en-US;q=0.8,en;q=0.6,ja;q=0.4,fr;q=0.2,it-IT;q=0.2,zh-CN;q=0.2,zh;q=0.2
Query String Parameters
api_key=xxx&session_id=xxx
Response Headers
HTTP/1.1 404 Not Found
Cache-Control: public, max-age=36000
Content-Type: text/html;charset=utf-8
Date: Sat, 26 Apr 2014 01:30:50 GMT
Server: nginx
Status: 404 Not Found
X-Cascade: pass
Content-Length: 18
Connection: keep-alive

As you can see, following that method I get a 404 error. Quite strange.... (session_id is correctly authorized and the account id is right, becaus i can retrieve the items from the lists).

Andrea

As a side note, here is the code that I use to add a move to favorite (with success). It's a jquery ajax call:

$.ajax({
        type: 'POST',
        url: theMovieDb.common.base_uri + "account/" + options.id + "/favorite?api_key=xxx&session_id=xxx,
        data: body,
        async:false,
        crossDomain: true,
        dataType:'json',
        success: function(mret)
        {
            success(JSON.stringify(mret));
        },
        error:function(error)
        {
            error(JSON.stringify(error));
        }
    });

where the body data is:

body = {
        "movie_id": '8765', 
        "favorite": 'true'
    }

Here is the network log:

Request URL:http://api.themoviedb.org/3/account/6131604/favorite?api_key=xxx&session_id=xxx
Request Method:POST
Status Code:201 Created
Request Headersview parsed
POST /3/account/6131604/favorite?api_key=xxx&session_id=xxx HTTP/1.1
Host: api.themoviedb.org
Connection: keep-alive
Content-Length: 28
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:8888
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:8888/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: it,en-US;q=0.8,en;q=0.6,ja;q=0.4,fr;q=0.2,it-IT;q=0.2,zh-CN;q=0.2,zh;q=0.2
Query String Parametersview parsed
api_key=xxx&session_id=xxx
Form Dataview parsed
movie_id=8765&favorite=false
Response Headersview parsed
HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Cache-Control: public, max-age=0
Content-Type: application/json;charset=utf-8
Date: Sat, 26 Apr 2014 10:31:36 GMT
Server: nginx
Status: 201 Created
Content-Length: 79
Connection: keep-alive

As you can see, it returns a status 201 created. Avoiding to set the request header content type to "application/json", it performs a correct POST request, but it doesn't send properly a json object in the body but a Form Data object. Differently from the example in the previous reply (copied from the api doc), this one has an apparent success... BUT, using the same code with a favorite = false, it returns the same result (and the same status code) without removing the movie from the favorite list.

In few words, the strange thing is that even if passing a not well formed (according to the api doc) json in body data of the request, the server side can read the movie_id and add it to the favorite list as well. But passing a false value for "favorite" it doesn't work. In the other hand, if you pass a correct header "content type" and "accept", and the json as body data, you have a bad request as posted in the previous reply.

I hope this can help.

Andrea

Was about to post the same problem. Removing an item from the watchlist has the same issue as removing an item from the favorite list. Has this already been looked into?

Thank you very much.

Turns out this was 2 things, one of which required an addition to the API.

First, while we support JSONP for GET requests, we don't truly for POST. In these examples, jQuery was attempting to make an OPTIONS call to the API first to see what remote CORS calls it is allowed to make. So I added a valid OPTIONS method for the API calls that need it. A local HTTP call through something like cURL doesn't require this.

Second, you weren't serializing your JSON properly. You need to pass a valid JSON object back to the server. I put a working session example online which you can see here. You can see on line 50, you need to make sure to JSON.parse(OBJECT) so that you're sending valid JSON.

Cheers.

Thank you, Travis.

Now everything is working properly. Tested in favorite and in watch_list.

Thanks again for your support and for your great work.

A.

Hi again,

It does say: The item/record was updated successfully. but it doesn't update the record for some reason...

I can't figure it out, it is the same call with one property changed.... Can someone help?

Kind regards,

Johnny

Hi shinta187,

Can you see the difference if you pass the "true" / "false" in as an actual boolean and not a string? Ie.

-d '{"media_id":240832,"media_type":"movie","favorite":false}'

Let me know.

Hi Travis,

That did the trick, thanks alot, it works now in curl. Working on a movies app as well. If the app is done, can i send you guys a message so that the app can be featured on the site after review?

Kind Regards

Yup, for sure. We usually look for apps that feature more functionality than not (ie. account and/or session features, maybe use of discover). You can email travis@themoviedb.org when you're ready.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login