0

roster xml format

Can you give us the xml format for a roster HTTP POST?

by
19 Replies
  • QUOTE (joeyjoejoe61 @ Jul 12 2010, 12:05 PM) <{POST_SNAPBACK}>
    Can you give us the xml format for a roster HTTP POST?

    CODE
    <fantasy_content>
    <roster>
    <coverage_type>date</coverage_type>
    <date>(coverage_value)</date>
    <players>
    <player>
    <player_key>(player_key)</player_key>
    <position>(position)</position>
    </player>
    ...
    </players>
    </roster>
    </fantasy_content>


    • The coverage_type should be "date" for Baseball, Hockey, and Basketball. It should be "week" for Football, which means you should have a <week> element (instead of a <date> element) for which week you're changing the roster for.
    • The player_key is the standard player_key, ie, mlb.p.6619.
    • The position should be whichever position slot you want to move the player to, with BN indicating bench.
    • You should PUT this up to the server, and your app needs to have read/write access. You only need to include player elements for any players that you want to change.


    I think that should cover it.
    0
  • QUOTE (Sean Montgomery @ Jul 12 2010, 07:57 PM) <{POST_SNAPBACK}>
    CODE
    <fantasy_content>
    <roster>
    <coverage_type>date</coverage_type>
    <date>(coverage_value)</date>
    <players>
    <player>
    <player_key>(player_key)</player_key>
    <position>(position)</position>
    </player>
    ...
    </players>
    </roster>
    </fantasy_content>


    • The coverage_type should be "date" for Baseball, Hockey, and Basketball. It should be "week" for Football, which means you should have a <week> element (instead of a <date> element) for which week you're changing the roster for.
    • The player_key is the standard player_key, ie, mlb.p.6619.
    • The position should be whichever position slot you want to move the player to, with BN indicating bench.
    • You should PUT this up to the server, and your app needs to have read/write access. You only need to include player elements for any players that you want to change.


    I think that should cover it.


    Is this missing a teamkey? I don't see anywhere in the xml file where the team is specified, so I'm not sure how to specify which team the roster move would take effect.
    0
  • QUOTE (joeyjoejoe61 @ Jul 13 2010, 10:25 AM) <{POST_SNAPBACK}>
    Is this missing a teamkey? I don't see anywhere in the xml file where the team is specified, so I'm not sure how to specify which team the roster move would take effect.


    I'm assuming it is in the url then? could you post the url?
    0
  • Oh, sorry about that. It's supposed to be a somewhat RESTful request, which means that you're PUTting up the XML to the resource that you're trying to replace. So the URL should be something like:

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/team/<team_key>/roster


    That should be sufficient to identify the team_key; you have the players and week/date in the XML, so that should cover the rest. Heh, I actually didn't write that part, but I'm pretty sure that's how it should work. Let me know if you're still having issues.
    0
  • QUOTE (Sean Montgomery @ Jul 14 2010, 09:18 PM) <{POST_SNAPBACK}>
    Oh, sorry about that. It's supposed to be a somewhat RESTful request, which means that you're PUTting up the XML to the resource that you're trying to replace. So the URL should be something like:

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/team/<team_key>/roster


    That should be sufficient to identify the team_key; you have the players and week/date in the XML, so that should cover the rest. Heh, I actually didn't write that part, but I'm pretty sure that's how it should work. Let me know if you're still having issues.


    Hi Sean,

    So is doing a PUT to that URL with XML data the only way to make roster change? Can we post the data as parameters instead of XML, or in JSON format? Will POST work instead of PUT?

    I'm having some trouble with my platform and doing a PUT.

    Thanks

    David B.
    0
  • QUOTE (cybler @ Aug 24 2010, 11:23 AM) <{POST_SNAPBACK}>
    Hi Sean,

    So is doing a PUT to that URL with XML data the only way to make roster change? Can we post the data as parameters instead of XML, or in JSON format? Will POST work instead of PUT?

    I'm having some trouble with my platform and doing a PUT.

    Thanks

    David B.

    Hm. Right now, we only have the option to do it as an XML PUT, 'cause we were trying to be RESTful and that's the technically correct way to structure that sort of request. What sort of problems are you running into trying to do a PUT?
    0
  • QUOTE (Sean Montgomery @ Aug 25 2010, 02:24 PM) <{POST_SNAPBACK}>
    Hm. Right now, we only have the option to do it as an XML PUT, 'cause we were trying to be RESTful and that's the technically correct way to structure that sort of request. What sort of problems are you running into trying to do a PUT?


    Thanks for responding. I developing for Palm webOS which mostly uses JavaScript and Prototype on top. Prototype and many other helpers change PUT to POST automatically. So now I'm trying just a straigh XMLHttpRequest, but I'm not finding very good examples to know if I'm writting the request successfully or not. Not sure where to go from here.

    David
    0
  • QUOTE (Sean Montgomery @ Aug 25 2010, 02:24 PM) <{POST_SNAPBACK}>
    Hm. Right now, we only have the option to do it as an XML PUT, 'cause we were trying to be RESTful and that's the technically correct way to structure that sort of request. What sort of problems are you running into trying to do a PUT?


    Maybe this will help, been poking at the API while watching Wireshark. I have been able to send a PUT now, verified by Wireshark, but when I send a PUT for the above URL, I get OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\"

    If I change only the word PUT to GET and run it again, it runs fine and I get Roster data back for that team. So I have my URL all set correctly, it's been signed and everything should be in order.

    I also checked on my application on the website and it is set to "Read/Write" for Fantasy Sports. I double-checked my Consumer Key and Consumer Secret and they're all fine. I wen through the OAuth for my app, again tonight and it all worked fine.

    Any ideas why I would get the Authorization errors?

    Thanks!

    David
    0
  • QUOTE (cybler @ Aug 26 2010, 12:51 AM) <{POST_SNAPBACK}>
    Maybe this will help, been poking at the API while watching Wireshark. I have been able to send a PUT now, verified by Wireshark, but when I send a PUT for the above URL, I get OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\"

    If I change only the word PUT to GET and run it again, it runs fine and I get Roster data back for that team. So I have my URL all set correctly, it's been signed and everything should be in order.

    I also checked on my application on the website and it is set to "Read/Write" for Fantasy Sports. I double-checked my Consumer Key and Consumer Secret and they're all fine. I wen through the OAuth for my app, again tonight and it all worked fine.

    Any ideas why I would get the Authorization errors?

    Here is the code I'm using:

    CODE
        var xhr = new XMLHttpRequest();
    xhr.open("PUT", url, false);
    xhr.send();


    Thanks!

    David
    0
  • Ok, I've been digging more and have slept a few hours too...grin. I tried a Transactions POST to drop a player ("is_undroppable": "0") and got the same "Authorization Required" message from the API. Before running the POST, I run two GET calls that run fine. So when looking at the POST call, the URL is the same as when I do a GET, everything, including all my OAuth stuff is just appended to the URL.

    I don't think this works for POST and PUT and think I have to send the OAuth stuff in the headers?? That last part was the question. :DDavid
    0
  • Ha, man, now you're getting into the hard stuff. :D
  • You should see how I'm composing the base string here -- it's a concatenation (separated by &s) of the method, URL, and parameters. The parameters need to be exactly which parameters you pass up with the request, ie, if your layer automatically adds any extra in, you're in trouble. The method also needs to match the method you're using, so if you're constructing the whole URL yourself, you won't be able to use the same URL between a GET and a POST because they'd have different signatures. Is that possibly part of the problem?
0
  • QUOTE (Sean Montgomery @ Aug 26 2010, 08:42 PM) <{POST_SNAPBACK}>
    Ha, man, now you're getting into the hard stuff. :DDavid B.
    0
  • I have yet to find a good example of actually doing the POST or PUT to modify anything in the API. All I see is examples of the XML, but nothing with actual PHP code to do the POST. 

    :(

    QUOTE(David B @ 27 Aug 2010 12:12 AM)
    QUOTE (Sean Montgomery @ Aug 26 2010, 08:42 PM) <{POST_SNAPBACK}>
    Ha, man, now you're getting into the hard stuff. :DDavid B.

    0
  • $AddXML is filled with all the XML examples in the doc... 

    QUOTE(Mr. Bob Harris @ 12 Aug 2011 5:04 PM)
    Persistence I guess got me there. 

     if( $o->fetch( $URLS['transaction'],$AddXML,OAUTH_HTTP_METHOD_POST,array("content-type" => "application/xml")) ) {

    This seems to have been what I was missing in my PHP.


    0
  • Right,&nbsp; there are just so many libraries out there to try to help with interacting with OAuth that it seemed most straightforward to just give you the XML schema and let you guys go from there. But duly noted -- we can at least work on getting an example with the basic PHP OAuth library for posting into the <a href="http://developer.yahoo.com/fantasysports/guide/GettingStarted.html">Getting Started</a> section of the docs.
    0
  • Right,&nbsp; there are just so many libraries out there to try to help with interacting with OAuth that it seemed most straightforward to just give you the XML schema and let you guys go from there. But duly noted -- we can at least work on getting an example with the basic PHP OAuth library for posting into the Getting Started section of the docs.
    0
  • I hear ya on multiple libraries. Just that you gave an example of how to do the login and basic fetch with that one library, yet nothing on the post. The documentation out there in general were all over the place. I'm just happy that i was able to get it working. Now, just would be nice if the commish could make changes to everyones info like they can on the regular site.

    thanks!

    QUOTE(Sean Montgomery @ 12 Aug 2011 10:48 PM)
    Right,  there are just so many libraries out there to try to help with interacting with OAuth that it seemed most straightforward to just give you the XML schema and let you guys go from there. But duly noted -- we can at least work on getting an example with the basic PHP OAuth library for posting into the Getting Started section of the docs.
    0
  • Bob, 

    Can you please tell me, are you using POST method or PUT method in your PHP code?

    I tried using PUT method and the response that I'm receiving is oauth_problem="signature_invalid". Can you please provide us more info on your stuff? Lots of members are facing the same issue.

    Thanks.

    QUOTE(Mr. Bob Harris @ 13 Aug 2011 10:14 AM)
    I hear ya on multiple libraries. Just that you gave an example of how to do the login and basic fetch with that one library, yet nothing on the post. The documentation out there in general were all over the place. I'm just happy that i was able to get it working. Now, just would be nice if the commish could make changes to everyones info like they can on the regular site.

    thanks!

    QUOTE(Sean Montgomery @ 12 Aug 2011 10:48 PM)
    Right,  there are just so many libraries out there to try to help with interacting with OAuth that it seemed most straightforward to just give you the XML schema and let you guys go from there. But duly noted -- we can at least work on getting an example with the basic PHP OAuth library for posting into the Getting Started section of the docs.
    0
  • You definitely need to use PUT, not POST, when editing rosters.

    http://developer.yahoo.com/fantasysports/guide/roster-resource.html#roster-resource-PUT

    Oh, geez, you know, I didn't even realize that the basic PHP OAuth library doesn't seem to support write operations. :| Here's a PHP example constructing a POST and using CURL -- swap out the $method for PUT and you should be pretty well set. I'll work on updating the documentation to show something like this, too.

    This all assumes that you already have sent the user through the authorization flow already, which is detailed in:

    http://developer.yahoo.com/fantasysports/guide/GettingStarted.html#GettingStarted-sample

    So we'll step back in as of where we try to get an access token after the user has provided us with the verifier at the end of their browser auth flow.

    ------------------------------------------------------------------
    $o = new OAuth( $consumer_key, $consumer_secret,
                    OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI );

    $o->enableDebug();

    try {
      $o->setToken( $token, $token_secret );
      $response = $o->getAccessToken( 'https://api.login.yahoo.com/oauth/v2/get_token', $session_handle, $verifier );
    } catch( OAuthException $e ) {
      print $e->getMessage() . "\n";
      print $e->lastResponse . "\n";
      exit;
    }

    print_r( $response );
    print urlencode( $response['oauth_token'] ) . "\n";

    print "Got OAuth token\n";


    $realm = 'yahooapis.com';
    $url = "URL THAT YOU NEED TO PUT/POST TO";
    $oauth_consumer_key = $consumer_key;
    $oauth_signature_method = 'HMAC-SHA1';
    $oauth_nonce = rand( 0, 100000 );
    $oauth_timestamp = time();
    $oauth_version = "1.0";
    $oauth_token = $response['oauth_token'];

    $method = 'POST'; // Or 'PUT' if you need to PUT.
    $params = '';
    $params .= 'oauth_consumer_key=' . urlencode($oauth_consumer_key);
    $params .= '&oauth_nonce=' . urlencode($oauth_nonce);
    $params .= '&oauth_signature_method=' . urlencode($oauth_signature_method);
    $params .= '&oauth_timestamp=' . urlencode($oauth_timestamp);
    $params .= '&oauth_token=' . urlencode( $oauth_token );
    $params .= '&oauth_version=' . urlencode($oauth_version);

    $base_string = urlencode( $method ) . '&' . urlencode( $url ) . '&' .
      urlencode( $params );

    print 'Base string: ' . $base_string . "\n";
    $secret = urlencode( $consumer_secret ) . '&' . urlencode( $response['oauth_token_secret'] );
    $signature = base64_encode( hash_hmac( 'sha1', $base_string, $secret, true ) );

    print 'Signature: ' . $signature . "\n";

    $test_url = $url . '?' . $params . '&oauth_signature=' . urlencode( $signature );

    print 'Test URL: ' . $test_url . "\n";

    $postdata = '<fantasy_content><XML CONTENT></fantasy_content>';

    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-type: application/xml' ) );
     if( $method == 'POST' ) {
       curl_setopt( $ch, CURLOPT_POST, 1 );
       curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
     } else if( $method == 'PUT' ) {
      
       $putData = tmpfile();
       fwrite( $putData, $postdata );
       fseek( $putData, 0 );

       curl_setopt( $ch, CURLOPT_PUT, 1 );
       curl_setopt( $ch, CURLOPT_INFILE, $putData );
       curl_setopt( $ch, CURLOPT_INFILESIZE, strlen( $postdata ) );

     }
    curl_setopt( $ch, CURLOPT_URL, $test_url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

    $ycw_result = curl_exec( $ch );
    $ret_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

     if( $method == 'PUT' ) {
       fclose( $putData );
     }

    curl_close( $ch );

    print_r( $ycw_result );
    print 'Return code: ' . $ret_code . "\n";


    ------------------------------------------------------------------

    0
  • Recent Posts

    in Fantasy Sports API