Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Errors with Bulk Tip API #1104

Closed
jeresig opened this issue Jul 3, 2013 · 7 comments
Closed

Errors with Bulk Tip API #1104

jeresig opened this issue Jul 3, 2013 · 7 comments
Assignees

Comments

@jeresig
Copy link
Contributor

jeresig commented Jul 3, 2013

I'm hitting some weird errors with the bulk tip API (see #1084).

Specifically I'm doing a request that looks like:

curl https://www.gittip.com/khanacademy/tips.json -u API_KEY: -X POST -d'[{"username":"mitsuhiko","platform":"gittip","amount":6.5},{"username":"kennethreitz","platform":"gittip","amount":1.5},{"username":"wycats","platform":"gittip","amount":6},{"username":"jashkenas","platform":"github","amount":12.25},{"username":"jezdez","platform":"gittip","amount":5.5},{"username":"whit537","platform":"gittip","amount":4},{"username":"epriestley","platform":"github","amount":6.25},{"username":"cloudhead","platform":"github","amount":4},{"username":"isaacs","platform":"gittip","amount":3.75},{"username":"scottgonzalez","platform":"gittip","amount":2.25},{"username":"dmethvin","platform":"gittip","amount":3.25},{"username":"rdworth","platform":"gittip","amount":2.75},{"username":"mxcl","platform":"gittip","amount":5.5},{"username":"mdo","platform":"gittip","amount":1.5},{"username":"fat","platform":"github","amount":1.75},{"username":"Stuk","platform":"github","amount":1},{"username":"marijnh","platform":"gittip","amount":1},{"username":"ariya","platform":"github","amount":1},{"username":"dangrossman","platform":"gittip","amount":1},{"username":"petehunt","platform":"github","amount":3},{"username":"jordow","platform":"github","amount":2.5},{"username":"kamaulynder","platform":"github","amount":0.5},{"username":"pv","platform":"github","amount":1},{"username":"wesm","platform":"gittip","amount":0.25}]'

(Where API_KEY is replaced with the API key.) I get back an empty body with no error message. Any insight into what might be going wrong?

@ghost ghost assigned chadwhitacre Jul 3, 2013
@chadwhitacre
Copy link
Contributor

Try POST -d'tips=...'?

@chadwhitacre
Copy link
Contributor

Also, I was seeing float rounding errors, if you see that then do "amount": "1.25" (String instead of Number).

@chadwhitacre
Copy link
Contributor

Aaaaaaand gittip is the only supported platform so far. :(

@chadwhitacre
Copy link
Contributor

Looked into the POST body more. The API docs do say to POST back the same structure you GET, which is application/json, not application/x-www-form-urlencoded.

@chadwhitacre
Copy link
Contributor

Okay, fixed it up. Now tips.json takes application/json, as in your original example. However, be sure to set the Content-Type or else we'll try to parse it as application/x-www-form-urlencoded.

curl https://www.gittip.com/khanacademy/tips.json \
    -u API_KEY: \
    -X POST \
    -d'[...]' \
    -H"Content-Type: application/json"

jeresig referenced this issue Jul 4, 2013
Make sure the `curl` code example works and mention a couple of the gotchyas.
@jeresig
Copy link
Contributor Author

jeresig commented Jul 4, 2013

Thank you for the fixes and clarification, Chad! I tweaked the docs some more to make the example work, as well (by default curl uses "application/x-www-form-urlencoded", which is what made me so confused). I just tried running my script and it works great!

If others ever run across this ticket and are interested, this is how you would do the POST using node.js and the request lib.

    request.post({
        url: "https://www.gittip.com/khanacademy/tips.json",
        json: payload,
        auth: {
            user: API_KEY,
            pass: ""
        }
    }, function(err, res, body) {
        console.log(err, res, body);
    });

@jeresig jeresig closed this as completed Jul 4, 2013
@chadwhitacre
Copy link
Contributor

Yay! Yeah, sorry, forgot to mention the curl default. :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants