Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Pastebin API: Bad API Request

edited July 2015 in Development Firefox

I am unable to get the script below to work. I am trying to paste code using the PasteBin API.

After acquiring a valid API_USER_KEY, pasteFile() is executed but I get "Bad API request, invalid api_option" onload. I am not sure what I am doing wrong.

API_PASTE_NAME = encodeURI("API Testing"),
API_PASTE_CODE = encodeURI("Some really good code");

var params = "api_dev_key=" + API_DEV_KEY + "&api_user_name=" + API_USER_NAME + "&api_user_password=" + API_USER_PASSWORD;


GM_xmlhttpRequest({
    method: "POST",
    url: "http://pastebin.com/api/api_login.php",
    data: params,
    headers: { "Content-Type": "application/x-www-form-urlencoded", Referer: "http://pastebin.com" },
    onload: function (response)
    {
        if (response.status == 200)
        {
            API_USER_KEY = response.responseText; //We need the user key to make a private post
            pasteFile();
        }
    }
});

function pasteFile()
{
    var params2 = "api_dev_key=" + API_DEV_KEY + "&api_user_name=" + API_USER_NAME + "&api_user_password=" + API_USER_PASSWORD
    + "&api_user_key=" + API_USER_KEY + "&api_paste_expire_date=10M&api_paste_private=1&api_paste_format=js&api_paste_name=" + API_PASTE_NAME + "&api_paste_code=" + API_PASTE_CODE;

    console.info(params2);
    GM_xmlhttpRequest({
        method: "POST",
        url: "http://pastebin.com/api/api_post.php",
        data: params2,
        headers: { "Content-Type": "application/x-www-form-urlencoded", Referer: "http://pastebin.com" },
        onload: function (response)
        {
            console.log(response);
        }
    });
}

Comments

  • The API doc page lists javascript = JavaScript, not js.

  • You forget to set the api_option=paste in params2. I also think you need to use encodeURIComponent() instead of encodeURI().
  • Ouch! Seems obvious now.

    Thank you both. It works now :)
Sign In or Register to comment.