1

I am trying to access the Looker API of a self-hosted instance. I am very new to nodejs and not sure how to go about this. THis is the error I am getting:

node:_http_outgoing:742
    throw new ERR_INVALID_ARG_TYPE(
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received undefined
    at new NodeError (node:internal/errors:372:5)
    at write_ (node:_http_outgoing:742:11)
    at ServerResponse.write (node:_http_outgoing:707:15)
    at Server.<anonymous> (/Users/the_user/Dropbox/products/LookerBot/index.js:63:13)
    at Server.emit (node:events:527:28)
    at parserOnIncoming (node:_http_server:956:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v17.9.0

This is what I tried:

var http = require("http");

http.createServer(function(request, response) {
   response.writeHead(200, {
      'Content-Type': 'text/html'
   });
   const axios = require('axios');
   const qs = require('qs');
   const slack_key = 'xoxb-12345';
   const looker_client_id = 'GDKGKDRHJGKR123';
   const looker_client_secret = 'sdfgfd6789'
   const looker_url = `https://mylooker.cloud.looker.com:19999/client_id=${looker_client_id}&client_secret=${looker_client_secret}`;

   let dict = {
      "url": "https://mylooker.cloud.looker.com",
      "apiBaseUrl": looker_url,
      'clientId': looker_client_id,
      'clientSecret': looker_client_secret
   }
   console.log(dict)
   axios.get(looker_url, {}, {
         'client_id': looker_client_id,
         'client_secret': looker_client_secret
      })
      .then(response => console.log(response))
      .catch(error => console.log(error))

   let slack_API = 'https://slack.com/api';
   let the_text = new URL('https://mylooker.cloud.looker.com/x/123456789');
   const greet = () => {
      let messageArgs = {
         token: slack_key,
         channel: '#testing',
         text: the_text.toString()
      };
      post(messageArgs);
   };

   const post = async (args) => {
      const result = await axios.post(`${slack_API}/chat.postMessage`, qs.stringify(args));
      try {
         console.log(result.data);
      } catch (e) {
         console.log(e);
      }
   };

   greet();
   response.write(request.looker_url);
   response.end();
}).listen(19999);

I am trying to create lookerbot and need to build a simple Node.js application. The application needs to be able to reach, both, my Looker instance's API and Slack's API. I am trying to open up port 19999 in order to accesss the Looker API.

What am I doing wrong?

nb_nb_nb
  • 1,243
  • 11
  • 36
  • Please standardise the syntax of your code. es6 shorthand or function declarations, its hard on the eyes to follow . Secondly, your `post` function is async, you need to await it on `post(messageArgs)`, or do `post(messageArgs).then((res) => res);` since your closure is in a synchronous context. – Joel May 09 '22 at 11:59
  • @Joel, I am so new to this. I am not even sure how to fix what you are asking me to do – nb_nb_nb May 09 '22 at 12:02

0 Answers0