Here is my code:
import { axios } from "@pipedream/platform";
// To use previous step data, pass the `steps` object to the run() function
// Assuming `steps.trigger.event.body` is the incoming payload
// Get the body from the trigger step
async function run({ steps }) {
// Get the body from the trigger step
const originalBody = steps.trigger.event.body;
try {
// Stringify and parse the JSON to ensure it's valid
const formattedBody = JSON.stringify(originalBody, null, 2); // Beautified JSON string
const validJSON = JSON.parse(formattedBody); // Will throw an error if not valid JSON
// Set the export using the 'this' keyword
this.validJSON = validJSON;
} catch (e) {
console.error('Invalid JSON:', e);
// Handle the error appropriately, maybe stop the workflow or notify you
this.error = e.message;
}
}
I want to use validJSON as the body for a POST to an API.
But I have not been able to access it. It doesn’t show up as an export.