now get auths is not defined
Apologies for the oversight in my previous response. You should use auths.hubspot.oauth_access_token
instead of auths.hubspot.oauth_access_token
. Here’s the corrected code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps, $ }) { const rows = steps.read_worksheet.$return_value.data; const companies = rows.map((row) => { return { objectId: row[“Company ID”], properties: [ { name: “property_name”, value: row[“Value”] }, // Add more properties if needed ], }; }); for (const company of companies) { const properties = company.properties.map((prop) => ({ name: prop.name, value: prop.value, })); await axios(this, { method: “PATCH”, url: https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}
, headers: { “Content-Type”: “application/json”, Authorization: Bearer ${auths.hubspot.oauth_access_token}
, }, data: { properties, }, }); } return { companies }; }, });
still getting the same error
Apologies for the confusion earlier. I made a mistake in my previous response. Please use the following corrected code: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { const rows = steps.read_worksheet.$return_value.data; const companies = rows.map((row) => { return { objectId: row["Company ID"], properties: [ { name: "property_name", value: row["Value"] }, // Add more properties if needed ], }; }); for (const company of companies) { const properties = company.properties.map((prop) => ({ name: prop.name, value: prop.value, })); await axios(this, { method: "PATCH", url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`, headers: { "Content-Type": "application/json", Authorization: `Bearer ${$.auths.hubspot.oauth_access_token}`, }, data: { properties, }, }); } return { companies }; }, });
In this corrected code, I replaced auths.hubspot.oauth_access_token
with $.auths.hubspot.oauth_access_token
. This should resolve the error you encountered.
now get Cannot read properties of undefined (reading ‘hubspot’)
I apologize for the confusion earlier. It seems I made a mistake in my previous response. Please use the following corrected code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { hubspot: { type: "app", app: "hubspot", }, }, async run({ steps, $ }) { const rows = steps.read_worksheet.$return_value.data; const companies = rows.map((row) => { return { objectId: row["Company ID"], properties: [ { name: "property_name", value: row["Value"] }, // Add more properties if needed ], }; }); for (const company of companies) { const properties = company.properties.map((prop) => ({ name: prop.name, value: prop.value, })); await axios(this, { method: "PATCH", url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`, headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, data: { properties, }, }); } return { companies }; }, });
In this corrected code, I added the hubspot
prop to the component and replaced $.auths.hubspot.oauth_access_token
with this.hubspot.$auth.oauth_access_token
. This should resolve the error you encountered.
can you give me an example of what the steps.read_worksheet.$return_value.data should look like?
Certainly! The steps.read_worksheet.$return_value.data
should be an array of objects, where each object represents a row in the worksheet. Each object should have key-value pairs representing the column names and their corresponding values in the row. Here’s an example of what it might look like: on [ { "Company ID": "123", "Value": "Example Value 1" }, { "Company ID": "456", "Value": "Example Value 2" }, { "Company ID": "789", "Value": "Example Value 3" } ]
In this example, there are three rows in the worksheet, each with a “Company ID” and a “Value” column. The steps.read_worksheet.$return_value.data
array contains objects representing these rows with their respective values.
why am i getting "{“status”:“error”,“message”:“Invalid input JSON on line 1, column 15: Cannot deserialize value of type”
It seems like there might be an issue with the JSON input you’re sending in your API request. To help you better, I’ll need more information about the specific API request you’re making and the JSON payload you’re sending. Please provide the relevant code snippet and the JSON payload you’re using, so I can assist you in resolving the error.
this is the code I am using -
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
hubspot: {
type: "app",
app: "hubspot",
},
},
async run({ steps, $ }) {
const rows = steps.get_values_in_range.$return_value;
const companies = rows.map((row) => {
return {
objectId: row[0],
properties: [
{ name: "gk_current_arr", value: row[1] },
// Add more properties if needed
],
};
});
for (const company of companies) {
const properties = company.properties.map((prop) => ({
name: prop.name,
value: prop.value,
}));
await axios(this, {
method: "PATCH",
url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`,
},
data: {
properties,
},
});
}
return { companies };
},
});
It looks like you’re trying to update companies in HubSpot using the provided code. The issue might be related to the format of the properties
object in the data
field of your axios request. The HubSpot API expects the properties to be in a key-value format. Try updating the properties format like this: ```
const properties = {}; company.properties.forEach((prop) => { properties[prop.name] = prop.value; }); await axios(this, { method: “PATCH”, url: https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}
, headers: { “Content-Type”: “application/json”, Authorization: Bearer ${this.hubspot.$auth.oauth_access_token}
, }, data: { properties, }, });
can you give me the full code step including your fix?
Sure, here’s the updated code with the fix applied: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { hubspot: { type: "app", app: "hubspot", }, }, async run({ steps, $ }) { const rows = steps.get_values_in_range.$return_value; const companies = rows.map((row) => { return { objectId: row[0], properties: [ { name: "gk_current_arr", value: row[1] }, // Add more properties if needed ], }; }); for (const company of companies) { const properties = {}; company.properties.forEach((prop) => { properties[prop.name] = prop.value; }); await axios(this, { method: "PATCH", url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`, headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, data: { properties, }, }); } return { companies }; }, });
This code now correctly formats the properties
object as a key-value pair before sending it in the PATCH request to HubSpot API.
I’m hitting a rate limit on Hubspot api - how can i resolve
I understand that you’re encountering rate limits with the HubSpot API. To resolve this issue, you can: 1. Add a delay between API requests in your code using setTimeout
or a similar method. This will help you stay within the rate limits imposed by HubSpot. 2. If you’re on the Free tier of HubSpot, consider upgrading to a paid plan, as they might have higher rate limits. You can check their pricing and plans at https://pipedream.com/pricing. If you continue to face issues, please share more details about your use case and the frequency of your API requests, so I can provide more specific guidance.
with the following code can you add a delay between the api calls?
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
hubspot: {
type: "app",
app: "hubspot",
},
},
async run({ steps, $ }) {
const rows = steps.get_values_in_range.$return_value;
const companies = rows.map((row) => {
return {
objectId: row[0],
properties: [
{ name: "gk_current_arr", value: row[1] },
// Add more properties if needed
],
};
});
for (const company of companies) {
const properties = {};
company.properties.forEach((prop) => {
properties[prop.name] = prop.value;
});
await axios(this, {
method: "PATCH",
url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`,
},
data: {
properties,
},
});
}
return { companies };
},
});
I can add a delay between the API calls using the setTimeout
function wrapped in a Promise. Here’s the updated code with the delay added: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { hubspot: { type: "app", app: "hubspot", }, }, async run({ steps, $ }) { const rows = steps.get_values_in_range.$return_value; const companies = rows.map((row) => { return { objectId: row[0], properties: [ { name: "gk_current_arr", value: row[1] }, // Add more properties if needed ], }; }); const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); for (const company of companies) { const properties = {}; company.properties.forEach((prop) => { properties[prop.name] = prop.value; }); await axios(this, { method: "PATCH", url: `https://api.hubapi.com/crm/v3/objects/companies/${company.objectId}`, headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, data: { properties, }, }); // Add a delay between API calls (e.g., 1000 ms) await delay(1000); } return { companies }; }, });
In this example, I added a 1000 ms (1 second) delay between the API calls. You can adjust the delay duration by changing the value passed to the delay()
function.