Why Are We Experiencing a 401 Authorization Issue with Instantly Using the Proxy on Pipedream?

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

hey we’re getting a 401 authorization issue with Instantly (slug: “instantly”) for using the proxy. Here is the error we are getting. Could it be a misconfiguration that’s easily fixable with pipedream? It seems they added a new v1 version with a bearer key auth https://developer.instantly.ai/

Can you share the payload you’re sending?

yes this was the code

import * as pd from "@pipedream/sdk";

async function execute(input) {
  try {
    const client = pd.createBackendClient({
      environment: process.env.PIPEDREAM_ENVIRONMENT,
      credentials: {
        clientId: process.env.PIPEDREAM_CLIENT_ID,
        clientSecret: process.env.PIPEDREAM_CLIENT_SECRET,
      },
      projectId: process.env.PIPEDREAM_PROJECT_ID
    });

    const proxyRequestOptions = {
      searchParams: {
        account_id: input.account_id,
        external_user_id: input.external_user_id,
      }
    };

    // Extract lead data from the Data Cleaning node
    const customCodeOutput = input.ctx.custom_code;
    const leadData = customCodeOutput?.output?.lead;

    if (!leadData) {
      throw new Error("No lead data found in input.ctx.custom_code.output.lead");
    }

    // Validate required email field
    if (!leadData.email) {
      throw new Error("Lead email is required but not found in the data");
    }

    // Prepare the lead object for Instantly API
    const leadPayload = {
      email: leadData.email,
      first_name: leadData.first_name || "",
      last_name: leadData.last_name || "",
      company_name: leadData.company_name || "",
      phone: leadData.phone || "",
      website: leadData.website || "",
      personalization: leadData.personalization || "",
      custom_variables: leadData.custom_variables || {},
      skip_if_in_workspace: leadData.skip_if_in_workspace || false,
      skip_if_in_campaign: leadData.skip_if_in_campaign || false,
      skip_if_in_list: leadData.skip_if_in_list || false,
      verify_leads_on_import: leadData.verify_leads_on_import || false,
      lt_interest_status: leadData.lt_interest_status || 1
    };

    // Make the API request to create a lead in Instantly
    const appRequestConfig = {
      url: "https://api.instantly.ai/api/v2/leads",
      options: {
        method: "POST",
        headers: {
          "Content-Type": "application/json"
        },
        body: JSON.stringify(leadPayload)
      }
    };

    const response = await client.makeProxyRequest(proxyRequestOptions, appRequestConfig);

    // Return the response from Instantly API
    return { 
      output: {
        success: true,
        lead_created: response,
        email: leadData.email,
        message: "Lead successfully created in Instantly"
      }
    };

  } catch (error) {
    console.error("Error creating lead in Instantly:", error);
    throw new Error(`Failed to create lead in Instantly: ${error.message}`);
  }
}

it seems to be that the auth is not sending the bearer key for the v2 of api. the docs mention that they used something other than the bearer key before the v2 migration

could that be it?

Oh, interesting. Yea it’s possible. Can you try again?

That worked! Thank you

Nice, cool

Thanks for flagging

For sure! Thanks for the quick resolution :slightly_smiling_face: