Ad

POST Data To The Mojang Api With Node.js Using Request Module

- 1 answer

I am using node.js for a discord bot and I want to use the Request module to post a name to the mojang api and get a uuid back. here is my code:

var uuid = request.post({
        url:     'https://api.mojang.com/profiles/minecraft',
        name:    `${username}`
    }, function(error, response, body){
        console.log(body);
        return response.id;
    });
Ad

Answer

Like @willymarj said, the data is returned in the body, not the response object. You will also want to parse the JSON response into a javascript object.

var uuid = request.post({
        url:     'https://api.mojang.com/profiles/minecraft',
         name:    `${username}`
    }, function(error, response, body){
        return JSON.parse(body.id);
    });
Ad
source: stackoverflow.com
Ad