Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
Why is POST request showing undefined? Node JS

I am receiving a request response in the console.log, however when I try to post to Mastodon (similar site to Twitter), it posts as 'undefined'.

bot.js:

require('dotenv').config();
const Mastodon = require('mastodon-api');
var request = require('request');

console.log("Mastodon Bot starting...");

const M = new Mastodon({
    access_token: process.env.ACCESS_TOKEN,
    client_key: process.env.CLIENT_KEY,
    client_secret: process.env.CLIENT_SECRET,
    timeout_ms: 60*1000,
    api_url: 'https://botsin.space/api/v1/',
  })

  const options = {
    method: 'GET',
    url: 'https://apisite.com/steps',
    qs: {count: '3'},
    headers: {
      'X-RapidAPI-Key': 'secret-api-key',
      'X-RapidAPI-Host': 'site-host',
      useQueryString: true,
    },
  };

  request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(JSON.parse(body, undefined, 5));

  });
    const params = {
      status: request
    }

    M.post('/statuses', params, (error, params) => {
    if (error) {
        console.log(error);
    }
    else {
        console.log(params.request);
    }
    });

This posts "Mastodon bot is starting...", then the results of the API GET request to the console (the response body). However, it does not post the response body to /statuses in Mastodon itself, it just posts 'undefined'.

How can I post the response body that I get in the console, to Mastodon?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda