Howdy, Stranger!

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

In this Discussion

How are HTTP POST request done?

edited September 25 in Questions Posts: 1

Hello, I’m trying to make a discord message system using POST requests but can’t seem to make it work

Here is my code so far:

function setup()
    url="https://discord.com/api/v9/auth/login"
    params={ 
        ["method"] = "POST",
        ["data"] = {
            ["login"] = "email", 
            ["password"] = "password", 
            ["undelete"] = "false", 
            ["captcha_key"] = "null", 
            ["login_source"] = "null", 
            ["gift_code_sku_id"] = "null"
        },
        ["headers"] = {
            ["content-type"] = "application/json"
        }
    }

    http.request(url, success, fail, params)
end

function success(data,status,head)
    print("success")
    print(#data)
    print(status)
    print(head)  
end

function fail(data,status,head) 
    print("fail") 
    print(data)
    print(status)
    print(head)
end

The response I get is:

Request failed: bad request (400)

This is what the request looks like in JavaScript if that can help:

discord_login();
async function discord_login() {
  let req = new Request("https://discord.com/api/v9/auth/login");
  req.method = "POST";
  req.headers = { "content-type": "application/json" };
  let body = {
    "login":"email",   
    "password":"password",
    "undelete":false,
    "captcha_key":null,
    "login_source":null,
    "gift_code_sku_id":null};
  req.body = JSON.stringify(body);
  let json = await req.loadJSON();
  console.log(json)
};

Comments

  • edited September 26 Posts: 213
    Looks like the rest of your code is fine but you need to convert the payload into a json string rather than pass it a lua table. 'json.encode(your_payload)' should do the trick.
Sign In or Register to comment.