Server-side actions plugins. Help needed

Long story short I need to run http request from server-side actions but I cannot make it work.

Let me state that seems @bubble plugin API calls and API connectors are not able to automatically unzip and process API responses that are returned in any zipped format. For example, many API-s return responses with gzip format. It is possible to do a hack and get a zipped data from the plugin as a text and send it to server side actions plugin for unzipping. But this operation fails when node js encounters ‘bad’ symbol in the raw data literal that is passed to it.

This brought me to the idea of doing http request and response processing with server-side plugin. However, I failed to execute even a simple http call. First of all, from the server-side plugin announcement thread I read that Bubble waits for the promises with await call so I thought that my code which uses following verified code snippet should work.

const getContent = function(url) {
  // return new pending promise
  return new Promise((resolve, reject) => {
    // select http or https module, depending on reqested url
    const lib = url.startsWith('https') ? require('https') : require('http');
    const request = lib.get(url, (response) => {
      // handle http errors
      if (response.statusCode < 200 || response.statusCode > 299) {
         reject(new Error('Failed to load page, status code: ' + response.statusCode));
       }
      // temporary data holder
      const body = [];
      // on every content chunk, push it to the data array
      response.on('data', (chunk) => body.push(chunk));
      // we are done, resolve promise with those joined chunks
      response.on('end', () => resolve(body.join('')));
    });
    // handle connection errors of the request
    request.on('error', (err) => reject(err))
    })
};

getContent("https://bubble.io")

But it didn’t. So my question would be:

  1. How to fetch the response http call in bubble to use in the next workflow actions?
  2. How to make results of any async calculations available to bubble

I found the answer for the 1st point. I Missed Mishav’s point that context.request that is provided by plugin can be operated in synchronous mode. So if I want to return body I need to do

response = context.request(‘http://www.google.com’); // or context.request(options) for complex http calls
response.body

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.