This topic was automatically generated from Slack. You can find the original thread here.
can you write a step that will call on 2 different hubspot api endpoints based upon a variables value previously set
This topic was automatically generated from Slack. You can find the original thread here.
can you write a step that will call on 2 different hubspot api endpoints based upon a variables value previously set
Sure, I can help you with that. Here’s an example of a Pipedream component that calls two different HubSpot API endpoints based on a variable’s value: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { variableValue: { type: "string", label: "Variable Value", }, apiKey: { type: "string", label: "HubSpot API Key", }, }, async run({ $ }) { const endpoint1 = "https://api.hubapi.com/crm/v3/objects/contacts"; const endpoint2 = "https://api.hubapi.com/crm/v3/objects/deals"; const config = { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${this.apiKey}`, }, }; if (this.variableValue === "contacts") { config.url = endpoint1; } else if (this.variableValue === "deals") { config.url = endpoint2; } else { throw new Error("Invalid variable value. Please use 'contacts' or 'deals'."); } const response = await axios($, config); return response; }, });
In this example, you’ll need to provide the variableValue
prop with either “contacts” or “deals” and your HubSpot API key as apiKey
. The component will call the appropriate HubSpot API endpoint based on the value of variableValue
.
can you change so that the first api call is to a GET but the second API call is a PATCH?
Sure, I’ve updated the Pipedream component to make a GET request for the first API call and a PATCH request for the second API call based on the variableValue
prop: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { variableValue: { type: "string", label: "Variable Value", }, apiKey: { type: "string", label: "HubSpot API Key", }, }, async run({ $ }) { const endpoint1 = "https://api.hubapi.com/crm/v3/objects/contacts"; const endpoint2 = "https://api.hubapi.com/crm/v3/objects/deals"; let config = { headers: { "Content-Type": "application/json", "Authorization": `Bearer ${this.apiKey}`, }, }; if (this.variableValue === "contacts") { config = { ...config, method: "GET", url: endpoint1, }; } else if (this.variableValue === "deals") { config = { ...config, method: "PATCH", url: endpoint2, data: { // Add the data you want to update in the PATCH request }, }; } else { throw new Error("Invalid variable value. Please use 'contacts' or 'deals'."); } const response = await axios($, config); return response; }, });
Remember to replace the data
property in the PATCH request with the actual data you want to update.