Bad request, try again later. Am I doing something wrong?

52 views
Skip to first unread message

donny wals

unread,
Jan 14, 2013, 6:37:11 AM1/14/13
to leaguevine...@googlegroups.com
Hey,

I'm trying to update some properties on a tournament using javascript and the Leaguevine API.
When I do the PUT api call I get a 500: bad request response. The message in the json response says that it's the server at fault and that I should try again later. For some reason I believe that the fault is on my part. Does someone see anything wrong with the code (all the variables exist are not null/undefined)

$.ajax({
        url: config.api_url+config.tournamentID+'/',
        success: function(data) {
            if(typeof data !== 'object') {
                data = $.parseJSON(data);
            }
            
            console.log(data);
        },
        data: {
            name: "Hello name"
        },
        type: 'PUT',
        error: function(data) {
            if(typeof data !== 'object') {
                data = $.parseJSON(data);
            }
            
            console.log(data);
        },
        headers: {
            Authorization: 'bearer '+config.access_token
        }
    });

Thanks!

Mark Liu

unread,
Jan 16, 2013, 10:56:18 PM1/16/13
to leaguevine...@googlegroups.com
Hey Donny,

500 errors are always Leaguevine's fault. Even if you enter in gibberish, we should still send you back a nice 4xx error with some useful information. I'll look into our logs and figure out why we're not giving you a useful message.

That being said, our API communicates via JSON so your ajax call does need to be modified a bit in order for it to send data that Leaguevine will like.

I haven't tested this, but here are some modifications to your code (in bold) that will thoroughly specify you're using JSON as the request body as well as the fact that you are expecting it in the response. Hopefully some part of this is useful:

$.ajax({
        dataType: "json",
        data: JSON.stringify( { name: "Hello name" } ),
        contentType: "application/json",
        beforeSend: function(jqXHR, settings) {
             settings.accepts['json'] = "application/json";
        },
        url: config.api_url+config.tournamentID+'/',
        success: function(data) {
            if(typeof data !== 'object') {
                data = $.parseJSON(data);
            }
            console.log(data);
        },
        type: 'PUT',
        error: function(data) {
            if(typeof data !== 'object') {
                data = $.parseJSON(data);
            }
            console.log(data);
        },
        headers: {
            Authorization: 'bearer '+config.access_token
        }
    });

Mark


--
You received this message because you are subscribed to the Google Groups "Leaguevine Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/leaguevine-developers/-/iCU94wlmJREJ.
To post to this group, send email to leaguevine...@googlegroups.com.
To unsubscribe from this group, send email to leaguevine-devel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/leaguevine-developers?hl=en.



--
Mark Liu
630-738-9280
http://leaguevine.com
http://twitter.com/leaguevine
http://facebook.com/leaguevine
Reply all
Reply to author
Forward
0 new messages