Can Anyone Help Me Fix Errors in Connecting Bubble to Pipedream for API Automation?

This topic was automatically generated from Slack. You can find the original thread here.

Hello Folks

I’m a non-techie working on building my dream project and need some help with automation. I want to connect bubble to pipedream to trigger a third party API but been getting a lot of errors. Anyone who can help me fix the errors? ask-pi

Hey , could you share the screenshot of the error you’re facing?

here is the error

Thanks , I’ll check and get back to you soon

Explaining the error in depth. Troubleshooting Error: | Loom

, please ignore the previous one

Hey , I’ll ignore the error related to bubble.

For code issue, you can ask our bot @U05A7KLNALC for help. Just simply:

@U05A7KLNALC please help me find the error in this js code

console.log("hello world"

It looks like there’s a syntax error in your JavaScript code due to a missing parenthesis. The console.log statement should be closed with a parenthesis. Here’s the corrected code: console.log("hello world"); This correction closes the console.log function call properly with a parenthesis and adds a semicolon at the end, which is a good practice for JavaScript statements.

help me find error in this code

// To use any npm package, just import it
import axios from “axios”

export default defineComponent({
async run({ steps, $ }) {

let upload_url = steps.trigger.event.body.upload_url;
let file = steps.trigger.event.body.file_url;
console.log(file);

  // Fetch the file as a blob
  let response = await fetch(file);
  let blob = await response.blob();
  console.log(blob);

  // Create FormData instance and append the file
  let data = new FormData();
  data.append('file', blob, 'file.wav'); // Ensure you provide a filename

  // Configure the axios request
  let config = {
    method: 'put',
    maxBodyLength: Infinity,
    url: upload_url,
    headers: {
      'Content-Type': 'audio/wave',
      'x-api-key': 'FBPKkHG20U9aMif0DxrznaYYE3g7qpJy97ZPoaHB'
    },
    data: data
  };

await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});

// Reference previous step data using the steps object and return data to use it in future steps
return steps.trigger.event

},
})

It appears there are a few potential issues with the code you’ve provided. Let’s address them step by step: 1. Importing axios from “axios”: In Pipedream components, you should use the axios instance provided by @pipedream/platform for HTTP requests. This ensures that your HTTP requests leverage Pipedream’s retry logic and error handling. 2. Using fetch to get a blob: In Node.js environments (like Pipedream), fetch is not available by default. You would need to use axios or another HTTP client supported in Node.js to fetch the file. Since you’re already using axios, you can stick with it for downloading the file as well. 3. Setting the Content-Type header: When uploading files using FormData, you don’t need to manually set the Content-Type header to 'audio/wave' for the file being uploaded. FormData will handle the Content-Type of the request, including the boundary parameter. You should remove this header from your config. 4. Using FormData: Since FormData is primarily a web API, for it to work in Node.js, you’d typically need an additional package like form-data. However, since you’re uploading a single file, you might not need FormData if you can stream the file directly as the request body. 5. Authorization Header: The 'x-api-key' header is used in your request. Ensure this key should be kept secure and not exposed in shared or public code. Here’s a revised version of your code using @pipedream/platform’s axios and addressing the above points: ``` import { axios } from “@pipedream/platform”; import fs from “fs”; import FormData from “form-data”; export default defineComponent({ async run({ steps, $ }) { let upload_url = steps.trigger.event.body.upload_url; let file_url = steps.trigger.event.body.file_url; console.log(file_url); // Assuming file_url is a direct URL to the file you want to upload // First, download the file using axios const response = await axios($, { method: ‘get’, url: file_url, responseType: ‘stream’, }); // Now upload the file const formData = new FormData(); formData.append(‘file’, response.data, ‘file.wav’); const headers

Where do I use the authorization key?

To use the authorization key, you typically include it in the headers of your HTTP requests to authenticate and authorize your access to an API. The authorization key is often used as a Bearer token in the Authorization header. Here’s an example of how you can use it in a curl command to make an authenticated request: bash curl 'https://api.pipedream.com/v1/users/me' \ -H 'Authorization: Bearer <api_key>' Replace <api_key> with your actual API key. This pattern is common across many APIs, including Pipedream’s API, where you need to authenticate your requests using your API key. For more details on authorizing API requests on Pipedream, you can visit Pipedream’s API documentation.

, I’m afraid it’s beyond just coding error. Would appreciate if someone could help me

As we’re trying to integrate it with bubble for frontend and need the storage to be done on the backend along with sending it to the third party server

Based on the code you’ve provided, there are a few potential issues and improvements to consider: 1. Importing FormData: Your code uses FormData but doesn’t import it. While browsers provide FormData globally, in a Node.js environment like Pipedream, you need to import it. You can use the form-data package for this purpose. 2. Using fetch: The fetch function is not natively available in Node.js. You’re using axios for HTTP requests, which can also be used to download the file. Consider replacing the fetch call with an axios call to get the file as a stream. 3. Content-Type Header: The Content-Type header is set to 'audio/wave', but the correct MIME type for WAV files is 'audio/wav'. Also, when uploading files with FormData, you typically don’t need to set the Content-Type header manually, as FormData will set it, including the boundary parameter. 4. Security Concern: The API key is hardcoded in the source code. For security reasons, it’s better to use environment variables or Pipedream’s built-in secrets management to handle API keys. Here’s a revised version of your code with these considerations: ``` import { axios } from “@pipedream/platform”; import FormData from “form-data”; import fs from “fs”; import stream from “stream”; import { promisify } from “util”; export default defineComponent({ async run({ steps, $ }) { let upload_url = steps.trigger.event.body.upload_url; let file_url = steps.trigger.event.body.file_url; console.log(file_url); // Use axios to fetch the file as a stream const response = await axios($, { method: ‘get’, url: file_url, responseType: ‘stream’, }); // Create FormData instance and append the file stream const data = new FormData(); const pipeline = promisify(stream.pipeline); const tempFilePath = /tmp/file.wav; await pipeline(response.data, fs.createWriteStream(tempFilePath)); data.append(‘file’, fs.createReadStream(tempFilePath), ‘file.wav’); // Configure the axios request for upload let config = { method: ‘put’, url: upload_url, headers: { …data.getHeaders(), 'x-api

have you closed the above code?

It appears you’re asking about closing or finalizing a code snippet, possibly related to a specific context or programming task. However, without more details about the code or the specific context you’re referring to, it’s challenging to provide a precise answer. Could you please provide more information or clarify the context of your question? For example, are you asking about closing a database connection, ending a script gracefully, or something else?

, help me fix the error: Unterminated string constant (33:8)

Code:

import { axios } from “@pipedream/platform”;
import FormData from “form-data”;
import fs from “fs”;
import stream from “stream”;
import { promisify } from “util”;

export default defineComponent({
async run({ steps, $ }) {
let upload_url = steps.trigger.event.body.upload_url;
let file_url = steps.trigger.event.body.file_url;
console.log(file_url);

// Use axios to fetch the file as a stream
const response = await axios($, {
  method: 'get',
  url: file_url,
  responseType: 'stream',
});

// Create FormData instance and append the file stream
const data = new FormData();
const pipeline = promisify(stream.pipeline);
const tempFilePath = `/tmp/file.wav`;
await pipeline(response.data, fs.createWriteStream(tempFilePath));
data.append('file', fs.createReadStream(tempFilePath), 'file.wav');

// Configure the axios request for upload
let config = {
  method: 'put',
  url: upload_url,
  headers: {
    ...data.getHeaders(),
    'x-api

It looks like the error message “Unterminated string constant (33:8)” is likely due to a syntax error in your code. Based on the code snippet you’ve provided, the error might be related to how the string or code block is terminated. However, the provided code snippet appears to be cut off at the end, which might be where the actual issue lies. Given the context, it’s possible that the error is due to an incomplete string or code block near the end of your provided code. Unfortunately, the code snippet is cut off, so I can’t see the exact location of the error. To help you more effectively, could you please provide the complete code snippet or specify the exact part of the code where the error occurs? This will allow me to give you a more accurate solution.

import { axios } from “@pipedream/platform”;
import FormData from “form-data”;
import fs from “fs”;
import stream from “stream”;
import { promisify } from “util”;

export default defineComponent({
async run({ steps, $ }) {
let upload_url = steps.trigger.event.body.upload_url;
let file_url = steps.trigger.event.body.file_url;
console.log(file_url);

// Use axios to fetch the file as a stream
const response = await axios($, {
  method: 'get',
  url: file_url,
  responseType: 'stream',
});

// Create FormData instance and append the file stream
const data = new FormData();
const pipeline = promisify(stream.pipeline);
const tempFilePath = `/tmp/file.wav`;
await pipeline(response.data, fs.createWriteStream(tempFilePath));
data.append('file', fs.createReadStream(tempFilePath), 'file.wav');

 // Configure the axios request
  let config = {
    method: 'put',
    maxBodyLength: Infinity,
    url: upload_url,
    headers: {
      'Content-Type': 'audio/wave',
      'x-api-key': 'FBPKkHG20U9aMif0DxrznaYYE3g7qpJy97ZPoaHB'
    },
    data: data
  };

await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
// Reference previous step data using the steps object and return data to use it in future steps
return steps.trigger.event
},
})

, help solve fort this error: The “body” argument must be of type function or an instance of Blob, ReadableStream, WritableStream, Stream, Iterable, AsyncIterable, or Promise or { readable, writable } pair. Received undefined

It seems like you’re encountering an issue with the axios request configuration, specifically related to how the file data is being sent in the request. The error message suggests that the data being passed to axios is not in an expected format. In your code, you’re using FormData to append a file, which is correct for multipart/form-data content types, but your request is configured with a Content-Type of audio/wave. This discrepancy might be causing the issue because you’re sending the request as if it’s a single file with a specific content type, rather than using multipart/form-data. Here’s a revised approach that might solve the issue: 1. Since you’re uploading an audio file and setting the Content-Type to audio/wave, you might not need FormData. Instead, you can directly stream the file content as the request body. 2. Ensure the Content-Type header matches the type of content you’re uploading. If you’re uploading a .wav file directly, your current header is correct. However, if you’re trying to upload using multipart/form-data, you’ll need to adjust this. Here’s a simplified version of your code for directly uploading a file without FormData, assuming the API you’re uploading to expects the file content directly with the Content-Type set to audio/wave: ``` import { axios } from “@pipedream/platform”; import fs from “fs”; export default defineComponent({ async run({ steps, $ }) { let upload_url = steps.trigger.event.body.upload_url; let file_url = steps.trigger.event.body.file_url; console.log(file_url); // Use axios to fetch the file as a stream const response = await axios($, { method: ‘get’, url: file_url, responseType: ‘stream’, }); // Temporary file path const tempFilePath = /tmp/file.wav; // Stream the response to a file response.data.pipe(fs.createWriteStream(tempFilePath)); // Wait for the file to finish writing await new Promise((resolve, reject) => { response.data.on(‘end’, resolve); response.data.on(‘error’, reject); }); // Configure the axios request for upload let config = { method: ‘put’, maxBodyLength: Infinity, url: upload_url, headers