How to Modify the Given Code to Retrieve Hubspot Engagements?

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

the following code, modify it to get hubspot engagements:
import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: ISSUE ${issue.number}: ${issue.title},
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

To modify the provided code to get HubSpot engagements, you’ll need to adjust the props to use HubSpot instead of GitHub, and change the API request to target HubSpot’s engagements API endpoint. Here’s how you can do it: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "Source Demo", description: "This is a demo source", props: { hubspot: { type: "app", app: "hubspot", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 * 60, // Adjust the interval as needed }, }, }, dedupe: "greatest", async run({ steps, $ }) { const data = await axios($, { method: "get", headers: { Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, url: `https://api.hubapi.com/engagements/v1/engagements/paged`, // HubSpot engagements API endpoint params: { // Include any necessary parameters here limit: 100, // Example parameter: adjust the limit as needed }, }); data.engagements.forEach((engagement) => { this.$emit(engagement, { id: engagement.engagement.id, summary: `Engagement ${engagement.engagement.id}`, ts: engagement.engagement.createdAt && +new Date(engagement.engagement.createdAt), }); }); }, }); Please note the following changes: - The props now include hubspot instead of github. - The Authorization header uses this.hubspot.$auth.oauth_access_token for HubSpot’s OAuth token. - The url is updated to HubSpot’s engagements API endpoint. You might need to adjust the URL or parameters based on your specific needs and what the HubSpot API expects. - The data processing part is adjusted to fit the structure of the response from HubSpot’s engagements API. You’ll need to modify this part based on the actual structure of the response you receive from HubSpot.

the following code, modify it to get hubspot engagements with the relevant fields :

import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: ISSUE ${issue.number}: ${issue.title},
body: issue.body,
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

To modify the provided code to get HubSpot engagements with relevant fields, you’ll need to adjust the props to use HubSpot instead of GitHub, and modify the API request to target HubSpot’s engagements API endpoint. Here’s how you can do it: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HubSpot Engagements Source", description: "Fetches HubSpot engagements", props: { hubspot: { type: "app", app: "hubspot", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 * 60, // Adjust the interval as needed }, }, }, dedupe: "greatest", async run({ steps, $ }) { const data = await axios($, { method: "get", url: `https://api.hubapi.com/engagements/v1/engagements/paged`, params: { // Include any relevant query parameters here limit: 100, // Example: Adjust the limit as needed }, headers: { Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, }); // Assuming the engagements data is in data.engagements data.engagements.forEach((engagement) => { this.$emit(engagement, { id: engagement.engagement.id, summary: `Engagement ID: ${engagement.engagement.id}`, body: JSON.stringify(engagement), // Emitting the whole engagement object as a string for simplicity ts: engagement.engagement.createdAt && +new Date(engagement.engagement.createdAt), }); }); }, }); Please note the following adjustments: 1. Changed the props to use hubspot instead of github. 2. Updated the axios request to target HubSpot’s engagements endpoint. You might need to adjust the URL and parameters according to the specific data you’re looking for. The HubSpot API documentation can provide more details on the available endpoints and their parameters. 3. Modified the $emit call to use fields relevant to HubSpot engagements. You may need to adjust these based on the specific fields you’re interested in. Remember to replace the placeholder values and parameters with the ones that match your requirements.

the following code, modify it to get hubspot meetings, using the v3, not legacy docs

import { axios } from “@pipedream/platform”;

export default {
name: “Source Demo”,
description: “This is a demo source”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run() {
const data = await axios(this, {
method: “get”,
headers: {
Authorization: Bearer ${this.github.$auth.oauth_access_token},
},
url: https://api.github.com/repos/pddemo/demo/issues,
});
data.forEach((issue) => {
this.$emit(issue, {
id: issue.id,
summary: ISSUE ${issue.number}: ${issue.title},
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

To modify the provided code to get HubSpot meetings using the v3 API, you’ll need to change the props to use the HubSpot app instead of GitHub, and update the API request URL and method accordingly. Here’s how you can adjust the code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "Source Demo", description: "This is a demo source", props: { hubspot: { type: "app", app: "hubspot", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 * 60, }, }, }, dedupe: "greatest", async run({ steps, $ }) { return await axios($, { method: "GET", url: `https://api.hubapi.com/crm/v3/objects/meetings`, headers: { Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, }); }, }); This code snippet is tailored to fetch meetings from HubSpot using their v3 API. Make sure to replace the app property from github to hubspot and update the Authorization header to use HubSpot’s OAuth access token. The request URL has been updated to the v3 endpoint for retrieving meetings.

the following ocde you provided, i need it to emit any data :

import { axios } from "@pipedream/platform";

export default defineComponent({
  name: "Source Demo",
  description: "This is a demo source",
  props: {
    hubspot: {
      type: "app",
      app: "hubspot",
    },
    timer: {
      type: "$.interface.timer",
      default: {
        intervalSeconds: 15 * 60,
      },
    },
  },
  dedupe: "greatest",
  async run({ steps, $ }) {
    return await axios($, {
      method: "GET",
      url: `https://api.hubapi.com/crm/v3/objects/meetings`,
      headers: {
        Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`,
      },
    });
  },
});

To modify the provided code so it emits data instead of returning it directly, you can use the $emit method. This method is used to emit data from a Pipedream source, allowing the emitted data to be used in subsequent steps of a workflow or observed in the source’s logs. Here’s how you can adjust your code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "Source Demo", description: "This is a demo source", props: { hubspot: { type: "app", app: "hubspot", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 * 60, }, }, }, dedupe: "greatest", async run({ steps, $ }) { const response = await axios($, { method: "GET", url: `https://api.hubapi.com/crm/v3/objects/meetings`, headers: { Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, }); // Emit the data so it can be used in subsequent steps this.$emit(response, { summary: "New HubSpot Meeting Data", id: response.data.id, // Assuming each meeting has a unique ID for deduplication ts: Date.now(), // Timestamp for when the data was emitted }); }, }); In this adjusted code, the axios call remains the same, but instead of returning the response directly, it’s passed to this.$emit along with a metadata object. The metadata object includes a summary that describes the emitted data, an id for deduplication purposes (assuming each meeting has a unique ID, you might need to adjust this based on the actual structure of the response), and a timestamp (ts) indicating when the data was emitted.

is the following code correct considering both pipedream and hubspot docs ?

import { axios } from “@pipedream/platform”;

export default defineComponent({
name: “Source Demo”,
description: “This is a demo source”,
props: {
hubspot: {
type: “app”,
app: “hubspot”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
const meetings = await axios($, {
method: “GET”,
url: https://api.hubapi.com/crm/v3/objects/meetings,
headers: {
Authorization: Bearer ${this.hubspot.$auth.oauth_access_token},
},
});

meetings.data.forEach((meeting) => {
  this.$emit(meeting, {
    id: meeting.id,
    subject: meeting.subject,
    description: meeting.description,
    createdAt: meeting.created_at,
    meetingUrl: meeting.meetingUrl,
    meetingType: meeting.meetingType,
    startDateTime:
      meeting.startDateTime && new Date(startDateTime).getTime(), // Convert to timestamp if needed
  });
});

},
});

The code you’ve provided is mostly correct and aligns with both Pipedream’s and HubSpot’s documentation standards for making API requests and defining components. However, there are a few areas that need attention for accuracy and functionality: 1. URL String Formatting: The URL in the axios request is enclosed in angle brackets < >, which is not correct. You should remove these brackets to correctly format the URL string. 2. Accessing meeting Properties: In the forEach loop, you’re using arrow function syntax correctly but using => instead of =>. This seems to be a formatting issue and should be corrected to =>. 3. Date Conversion: The startDateTime conversion uses a variable startDateTime that is not defined in the scope of the function where it’s used. You should use meeting.startDateTime instead of startDateTime directly. Also, the logical AND operator && is incorrectly encoded and should be &&. 4. Error Handling: It’s good practice to include error handling when making API requests to manage any exceptions or errors that may occur during the request. Here’s a revised version of your code with the above corrections: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ name: “Source Demo”, description: “This is a demo source”, props: { hubspot: { type: “app”, app: “hubspot”, }, timer: { type: “$.interface.timer”, default: { intervalSeconds: 15 * 60, }, }, }, dedupe: “greatest”, async run({ steps, $ }) { try { const meetings = await axios($, { method: “GET”, url: https://api.hubapi.com/crm/v3/objects/meetings, headers: { Authorization: Bearer ${this.hubspot.$auth.oauth_access_token}, }, }); meetings.data.forEach((meeting) => { this.$emit(meeting, { id: meeting.id, subject: meeting.subject, description: meeting.description, createdAt: meeting.created_at, meetingUrl: meeting.meetingUrl, meetingType: meeting.meetingType, startDateTime: meeting.startDateTime && new Date(meeting.startDateTime).getTime(),