Hi, I'm trying to add a transformation with an ext...
# support
f
Hi, I'm trying to add a transformation with an external API requests to enrich events with Clearbit Reveal data and append to event object. Followed some of the transformation examples but the output is still missing the response from API request.
m
Hey There! 👋 Your message has been received by the RudderStack team. We will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
f
Here's the transformation code:
Copy code
export async function transformEvent(event, metadata) {
    if (event.request_ip) {
        try {
            const apiKey = "<SECRET_CLEARBIT_KEY>;
            const apiUrl = `https://reveal.clearbit.com/v1/companies/find?ip=${event.request_ip}`;

            const res = await fetch(apiUrl, {
                method: "GET",
                headers: {
                    "Authorization": `Bearer ${apiKey}`
                }
            });

            if (res.status === 200) {
                const revealData = await res.json();
                event.context.reveal = revealData;
            }
        } catch (error) {
            // Handle errors
        }
    }

    return event;
}
h
@fresh-state-3227 assume you have a clearbit enterprise plan?
t
@fresh-state-3227 it may be because the
fetch
call already includes
res.json()
Can you try something closer to the built template? Did this not work for you?
Copy code
export async function transformEvent(event) {
    const email = event.context?.traits?.email;
    if (email) {
        const res = await fetch("<https://person.clearbit.com/v2/combined/find?email=>" + email, {
            headers: {
                "Authorization": "Bearer <your_clearbit_secure_key"
            }
        });
        event.context.traits.enrichmentInfo = res;
    }
    return event;
}
🙌 1
f
Thanks for the help guys! @tall-lawyer-58398 you're right, changing
res.json()
to
res
solved it.