This topic was automatically generated from Slack. You can find the original thread here.
Hi everyone! i have a url to a password protected JSON file. This contains a JSON object with customers that each have an email and a revenue number. Now i would like to get those 2 values for each customer with pipedream, look the email up in HubSpot and if that email exists i would like to push the revenue number to that customer, is that possible?
Hello , I will pass your question to the new Pipedream bot support in order to evaluate its usefulness. I think it can provide quite a decent answer for you
Hi everyone! i have a url to a password protected JSON file. This contains a JSON object with customers that each have an email and a revenue number. Now i would like to get those 2 values for each customer with pipedream, look the email up in HubSpot and if that email exists i would like to push the revenue number to that customer, is that possible?
Hello! Yes, it’s possible to achieve this using Pipedream. First, you’ll need to fetch the JSON data from the password-protected URL. You can use the axios package to make an HTTP request with authentication. Then, you can iterate through the customers and use the HubSpot integration to search for the email and update the customer’s revenue if the email exists. Here’s a sample Pipedream component to help you get started: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { url: { type: "string", label: "URL to the JSON file", }, username: { type: "string", label: "Username for authentication", }, password: { type: "string", label: "Password for authentication", }, }, async run({ $ }) { // Fetch the JSON data from the password-protected URL const response = await axios($, { method: "GET", url: this.url, auth: { username: this.username, password: this.password, }, }); // Iterate through the customers for (const customer of response) { const email = customer.email; const revenue = customer.revenue; // Search for the email in HubSpot const searchResults = await this.$hubspot.searchContactsByEmail(email); // If the email exists, update the customer's revenue if (searchResults.length > 0) { const contactId = searchResults[0].id; await this.$hubspot.updateContact(contactId, { revenue }); } } }, }); This component requires you to input the URL to the JSON file, and the username and password for authentication. It fetches the JSON data, iterates through the customers, and uses the HubSpot integration to search for the email and update the customer’s revenue if the email exists. Make sure to connect your HubSpot account to Pipedream to use the $hubspot methods. You can find more information on the HubSpot integration here: https://pipedream.com/apps/hubspot
I have a url to a password protected JSON file. This contains a JSON object with customers that each have an email and a revenue number. Now i would like to get those 2 values for each customer with pipedream, look the email up in HubSpot and if that email exists i would like to push the revenue number to that customer, is that possible? The integration code should include the code to import hubspot module from Pipedream public repository
Yes, it’s possible to achieve this using Pipedream. First, you’ll need to use the axios package to fetch the JSON data from the password-protected URL. Then, you can use the HubSpot integration in Pipedream to look up the email and update the customer’s revenue. Here’s an example Pipedream component that demonstrates how to do this: ```
import { axios } from “@pipedream/platform”; import hubspot from “@pipedreamhq/platform/hubspot”; export default defineComponent({ props: { url: { type: “string”, label: “URL to the JSON file”, }, username: { type: “string”, label: “Username for the password-protected URL”, }, password: { type: “string”, label: “Password for the password-protected URL”, }, apiKey: { type: “string”, label: “HubSpot API Key”, }, }, async run() { // Fetch the JSON data from the password-protected URL const response = await axios(this, { method: “GET”, url: this.url, auth: { username: this.username, password: this.password, }, }); // Initialize the HubSpot client const client = new hubspot.Client({ apiKey: this.apiKey }); // Iterate through the customers and update their revenue in HubSpot for (const customer of response) { const { email, revenue } = customer; // Look up the email in HubSpot const contact = await client.crm.contacts.basicApi.getByEmail(email); // If the email exists, update the customer’s revenue if (contact) { const contactId = contact.id; await client.crm.contacts.basicApi.update(contactId, { properties: { revenue: revenue, }, }); } } }, });
Sure, here’s an example of using the @pipedream/hubspot package in a Pipedream component: import { Hubspot } from "@pipedream/hubspot"; export default defineComponent({ props: { apiKey: { type: "string", label: "Hubspot API Key", secret: true, }, }, async run({ $ }) { const hubspot = new Hubspot(this.apiKey); // Example: Get all contacts const contacts = await hubspot.contacts.getAll(); console.log(contacts); return contacts; }, }); In this example, we import the Hubspot class from the @pipedream/hubspot package and create a new instance with the provided API key. Then, we use the hubspot.contacts.getAll() method to fetch all contacts and return them. Make sure to replace the example method with the one you’d like to use from the Hubspot package.
To update customers in Hubspot using Pipedream, you can create a workflow that reads the JSON file and makes API calls to Hubspot. Here’s a basic example of how to achieve this: 1. First, you’ll need to set up the Hubspot integration in Pipedream. Visit https://pipedream.com/apps/hubspot and follow the instructions to connect your Hubspot account. 2. Create a new Pipedream workflow and add a “Read File from URL” action. Configure the action with the URL of your JSON file and any required authentication (e.g., Basic Auth with a username and password). 3. Add a “Run Node.js code” step after the “Read File from URL” step. In this step, you’ll parse the JSON file and loop through the customers to update them in Hubspot. Here’s an example code snippet: import { axios } from "@pipedream/platform"; const customers = JSON.parse(steps.read_file_from_url.$return_value); for (const customer of customers) { const email = customer.email; const revenue = customer.revenue; // Find the Hubspot contact by email const searchContactResponse = await axios(this, { method: "GET", url: `https://api.hubapi.com/contacts/v1/contact/search/email/${email}`, params: { hapikey: process.env.HUBSPOT_API_KEY, }, }); if (searchContactResponse && searchContactResponse.vid) { // Update the contact with the revenue value const updateContactResponse = await axios(this, { method: "POST", url: `https://api.hubapi.com/contacts/v1/contact/vid/${searchContactResponse.vid}/profile`, params: { hapikey: process.env.HUBSPOT_API_KEY, }, data: { properties: [ { property: "revenue", value: revenue, }, ], }, }); } } Replace steps.read_file_from_url.$return_value with the reference to the output of the “Read File from URL” step. Also, make sure to store your Hubspot API key in a Pipedream environment variable named HUBSPOT_API_KEY. This example assumes that your JSON file contains an array of customer objects with email and revenue properties. Adjust the code
Hi , please ignore those answers. I think the first answer is nearly there. You will need to change some parts of the code:
You’ll need to add the hubspot app code into the props
The part that it calls this.$hubspot to the Hubspot API calls.
Here’s the sample Node.js code step to call to Hubspot API that you can use as additional reference