Hello,
I’m new a no knowledge from pipedream.
Two steps i created:
Step 1 http/webhook
Step 2 node.js with this code but i got error in flow
Who can help me ?
import axios from ‘axios’;
import qs from ‘qs’;
export default async (event, steps, $) => {
const authorizationCode = event.body.code; // Adjust based on how your data is sent
if (!authorizationCode) {
await $.respond({
immediate: true,
status: 400,
headers: { ‘Content-Type’: ‘application/json’ },
body: { message: ‘Authorization code not found in request body’ }
});
return;
}
const data = {
client_id: ‘XXXXXXXXXXXXX’,
client_secret: ‘XXXXXXXXXXXXX’,
code: authorizationCode,
redirect_uri: ‘XXXXXXXXXXXXX’,',
grant_type: ‘authorization_code’
};
try {
const response = await axios.post(‘Sign in to your account’, qs.stringify(data), {
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’
}
});
await $.respond({
immediate: true,
status: 200,
headers: { 'Content-Type': 'application/json' },
body: {
success: true,
status_code: response.status,
headers: response.headers,
body: response.data
}
});
} catch (error) {
await $.respond({
immediate: true,
status: 500,
headers: { ‘Content-Type’: ‘application/json’ },
body: {
success: false,
status_code: error.response ? error.response.status : ‘N/A’,
headers: error.response ? error.response.headers : ‘N/A’,
body: error.response ? error.response.data : error.message
}
});
}
};