Why is the Apollo API Key Not Being Passed Correctly When Using the Pipedream Proxy?

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

hey guys, getting an issue with the apollo api using the pipedream proxy. It’s saying that the api key is not being passed in correctly. Info on the error and the code in the thread

Error:

Error searching people in Apollo: Error: HTTP error! status: 422, body: {"error":"API key must be passed in the X-Api-Key header for security reasons. Refer to the documentation for more details: https://docs.apollo.io/docs/test-api-key","error_code":"INVALID_API_KEY_LOCATION"}\n' +
      '    at P.makeRequest (file:///root/.cache/riza-runtimes/01JY31BFEFPE0AF1WTV0GNEZR3/vendor/esm.sh//@pipedream/sdk@1.6.9/denonext/sdk.mjs:3:2379)\n' +
      '    at eventLoopTick (ext:core/01_core.js:178:7)\n' +
      '    at async execute (file:///main.js:34:22)\n' +
      '    at async main (file:///main.js:82:34)\n' +
      '    at async file:///main.js:103:1\n' +
      'Error: HTTP error! status: 422, body: {"error":"API key must be passed in the X-Api-Key header for security reasons. Refer to the documentation for more details: https://docs.apollo.io/docs/test-api-key","error_code":"INVALID_API_KEY_LOCATION"}\n' +
      '    at P.makeRequest (file:///root/.cache/riza-runtimes/01JY31BFEFPE0AF1WTV0GNEZR3/vendor/esm.sh//@pipedream/sdk@1.6.9/denonext/sdk.mjs:3:2379)\n' +
      '    at eventLoopTick (ext:core/01_core.js:178:7)\n' +
      '    at async execute (file:///main.js:34:22)\n' +
      '    at async main (file:///main.js:82:34)\n' +
      '    at async file:///main.js:103:1',
    duration: 1077
  }

Code:

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

async function execute(input) {
  // Guard clauses for required inputs
  if (!input.account_id || !input.external_user_id) {
    throw new Error(
      "Missing required inputs: `account_id` and `external_user_id` must be provided."
    );
  }

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

    // Request body for Apollo people search
    const searchPayload = {
      person_titles: [
        "CEO", "Chief Executive Officer",
        "CFO", "Chief Financial Officer",
        "CTO", "Chief Technology Officer",
        "COO", "Chief Operating Officer",
      ],
      q_organization_industries: ["Furniture"],
      page: 1,
      per_page: 10,
    };

    const response = await client.makeProxyRequest(
      {
        searchParams: {
          account_id: input.account_id,
          external_user_id: input.external_user_id,
        },
      },
      {
        // Full URL for the static Apollo API domain
        url: "https://api.apollo.io/v1/mixed_people/search",
        options: {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Accept": "application/json",
          },
          body: searchPayload,
        },
      }
    );

    return {
      output: Array.isArray(response?.people) ? response.people : [],
    };
  } catch (err) {
    console.error("Error searching people in Apollo:", err);
    throw err;
  }
}

Interesting. Can you try again? I just updated the app’s configuration.

perfect that fixed it! thank you

Nice, great — thanks for flagging!