Hi @rafael,
To achieve the task of downloading a GTMetrix report and uploading it to Google Drive with the required authentication, you can use a custom code step in your Pipedream workflow. This step will handle the authentication to GTMetrix, download the report, and then upload it to Google Drive. Here’s how you can do it:
-
Download the GTMetrix report using HTTP authentication: You’ll first need to download the report from GTMetrix using the provided URL and your GTMetrix API key for authentication.
-
Upload the downloaded file to Google Drive: Once you have the report, you can then upload it to Google Drive using the Google Drive API.
Here’s an example of how you can structure this custom code step in your workflow:
import { axios } from "@pipedream/platform";
import fs from "fs";
import path from "path";
export default defineComponent({
props: {
gtmetrix: {
type: "app",
app: "gtmetrix",
},
google: {
type: "app",
app: "google",
},
},
async run({ steps, $ }) {
// Define the GTMetrix report URL
const reportUrl = `https://gtmetrix.com/api/2.0/reports/MY_REPORT_ID/resources/report.pdf`;
// Download the GTMetrix report
const reportResponse = await axios($, {
url: reportUrl,
method: "GET",
responseType: "arraybuffer",
auth: {
username: `${this.gtmetrix.$auth.api_key}`,
password: ``,
},
});
// Save the report to a temporary file
const tempFilePath = path.join("/tmp", "gtmetrix_report.pdf");
fs.writeFileSync(tempFilePath, reportResponse, "binary");
// Upload the report to Google Drive
const driveResponse = await axios($, {
method: "POST",
url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=media",
headers: {
Authorization: `Bearer ${this.google.$auth.oauth_access_token}`,
"Content-Type": "application/pdf",
},
params: {
name: "gtmetrix_report.pdf",
},
data: fs.createReadStream(tempFilePath),
});
return driveResponse.data;
},
});
Note: This example assumes you
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double-check my answers and code! Learn how to build your own.