How to Add a Workspace ID Prop and Emit it in a Velora Github Team Discussions Source GET code?

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

in the following code add another prop for workspace id and emit it too:

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

export default defineComponent({
name: “velora-github-team-discussions-source-GET”,
description:
“This is a custom source for Velora AI, which fetches user credentials from an external source, and then uses the GET API to fetch GitHub team discussions, with 15-minute timer intervals.”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
org: {
type: “string”,
label: “Organization Name”,
description: “Enter the name of the GitHub organization.”,
},
team_slug: {
type: “string”,
label: “Team Slug”,
description: “Enter the slug of the GitHub team.”,
},
nango_connection_id: {
type: “string”,
label: “Nango Connection ID”,
description: “Enter the Nango Connection ID”,
},
nango_integration_id: {
type: “string”,
label: “Nango Integration ID”,
description: “Enter the Nango Integration ID”,
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
try {
// Retrieve the GitHub token from Nango
const nangoResponse = await axios($, {
method: “GET”,
headers: {
Authorization: Bearer ${process.env.VELORA_NANGO_SECRET_KEY},
},
url: https://api.nango.dev/connection/${this.nango_connection_id}?provider_config_key=${this.nango_integration_id},
});
const github_token = nangoResponse.credentials.access_token;

  // Use the GitHub token to make a request to the GitHub API for team discussions
  const data = await axios($, {
    method: "get",
    headers: {
      Authorization: `Bearer ${github_token}`,
      accept: "application/vnd.github+json",
    },
    url: `https://api.github.com/orgs/${this.org}/teams/${this.team_slug}/discussions`,
    params: {
      per_page: 100, // Adjust this value as needed
      page: 1, // Adjust this value as needed
    },
  });

  data.forEach((discussion) => {
    this.$emit(discussion, {
      id: discussion.id,
      summary: `DISCUSSION ${discussion.number}: ${discussion.title}`,
      body: discussion.body,
      ts: discussion.created_at && +new Date(discussion.created_at),
    });
  });
} catch (error) {
  // Handle errors gracefully
  $.error(`Failed to fetch discussions: ${error.message}`);
}

},
});

To add another prop for the workspace ID and emit it as part of the discussions, you can modify the provided code by adding a new prop named workspace_id and including it in the emitted data. Here’s how you can do it: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ name: “velora-github-team-discussions-source-GET”, description: “This is a custom source for Velora AI, which fetches user credentials from an external source, and then uses the GET API to fetch GitHub team discussions, with 15-minute timer intervals.”, props: { github: { type: “app”, app: “github”, }, timer: { type: “$.interface.timer”, default: { intervalSeconds: 15 * 60, }, }, org: { type: “string”, label: “Organization Name”, description: “Enter the name of the GitHub organization.”, }, team_slug: { type: “string”, label: “Team Slug”, description: “Enter the slug of the GitHub team.”, }, nango_connection_id: { type: “string”, label: “Nango Connection ID”, description: “Enter the Nango Connection ID”, }, nango_integration_id: { type: “string”, label: “Nango Integration ID”, description: “Enter the Nango Integration ID”, }, workspace_id: { type: “string”, label: “Workspace ID”, description: “Enter the Workspace ID”, }, }, dedupe: “greatest”, async run({ steps, $ }) { try { // Retrieve the GitHub token from Nango const nangoResponse = await axios($, { method: “GET”, headers: { Authorization: Bearer ${process.env.VELORA_NANGO_SECRET_KEY}, }, url: https://api.nango.dev/connection/${this.nango_connection_id}?provider_config_key=${this.nango_integration_id}, }); const github_token = nangoResponse.credentials.access_token; // Use the GitHub token to make a request to the GitHub API for team discussions const data = await axios($, { method: “get”, headers: { Authorization: `Bearer ${github_token

in the following code add another prop for workspace id and emit it too:
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 add another prop for the workspace ID and emit it, you can modify the component code as follows: 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, }, }, workspaceId: { // Adding the workspaceId prop type: "string", label: "Workspace ID", description: "The ID of the workspace", }, }, 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), workspaceId: this.workspaceId, // Emitting the workspaceId along with other data }); }); }, }; In this modification, a new props entry for workspaceId is added, which is of type string. This prop allows the user to input a workspace ID when configuring the component. The workspaceId is then emitted alongside each issue’s details.

the following code, modify it for hubspot tickets

To modify the provided example for HubSpot tickets, you’ll want to adjust the API endpoint and possibly the HTTP method or payload, depending on the specific action you’re trying to perform with HubSpot tickets (e.g., creating a ticket, retrieving tickets, updating a ticket). Unfortunately, the specific action wasn’t mentioned, so I’ll provide a general example of how to retrieve tickets from HubSpot using their API. First, ensure you’ve reviewed the HubSpot API documentation related to tickets to understand the required endpoint and any necessary parameters. The example below is based on a hypothetical scenario where we’re listing tickets. You might need to adjust the URL or parameters based on your specific needs. import { axios } from "@pipedream/platform"; export default defineComponent({ props: { hubspot: { type: "app", app: "hubspot", }, }, async run({ steps, $ }) { return await axios($, { url: `https://api.hubapi.com/crm/v3/objects/tickets`, method: "GET", headers: { Authorization: `Bearer ${this.hubspot.$auth.oauth_access_token}`, }, }); }, }); This code snippet is designed to make a GET request to the HubSpot API to list tickets. Note the following: - The URL https://api.hubapi.com/crm/v3/objects/tickets is used for listing tickets, according to the HubSpot API documentation. You might need to adjust this URL if you’re performing a different action with tickets. - The Authorization header uses the OAuth access token from the connected HubSpot account to authenticate the request. - The method is set to “GET” for retrieving data. If you’re creating or updating tickets, this might change to “POST” or “PATCH”, and you would also need to include a data property in the axios call with the payload. Remember to replace this example with the specific details of your use case, including the correct endpoint and any required parameters or payload.

the following code modify it to get hubspot tickets:

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 tickets instead of GitHub issues, you’ll need to adjust the props to use the HubSpot app, and modify the API request to fetch tickets from HubSpot’s API. Here’s how you can do it: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HubSpot Tickets Source", description: "Fetches HubSpot tickets on a schedule", 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}`, }, // Replace the URL with the endpoint for fetching tickets from HubSpot url: `https://api.hubapi.com/crm/v3/objects/tickets`, }); // Assuming the response structure is an array of tickets data.forEach((ticket) => { this.$emit(ticket, { id: ticket.id, summary: `TICKET ${ticket.id}: ${ticket.properties.subject}`, ts: ticket.createdAt && +new Date(ticket.createdAt), }); }); }, }); Please note: - You’ll need to adjust the url to the correct endpoint for fetching tickets from HubSpot. The example URL I’ve used (https://api.hubapi.com/crm/v3/objects/tickets) assumes you’re using the CRM Tickets API, but you should verify this against the HubSpot API documentation. - The way you access ticket properties (ticket.properties.subject and ticket.createdAt) might need to be adjusted based on the actual structure of the response from HubSpot’s API. - This example uses the $.interface.timer prop to run the source on a schedule, fetching new tickets every 15 minutes. Adjust the intervalSeconds as necessary for your use case.

the following code modify it to get hubspot tickets:

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 tickets instead of GitHub issues, you’ll need to adjust the props to use HubSpot’s app authentication, change the API request URL to HubSpot’s endpoint for fetching tickets, and update the data processing part accordingly. Here’s how you can do it: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HubSpot Tickets Source", description: "Fetches HubSpot tickets on a schedule", 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}`, }, // Update the URL to the endpoint for fetching tickets from HubSpot url: `https://api.hubapi.com/crm/v3/objects/tickets`, }); // Assuming the response data contains an array of tickets data.results.forEach((ticket) => { this.$emit(ticket, { id: ticket.id, summary: `TICKET ${ticket.id}: ${ticket.properties.subject}`, ts: ticket.createdAt && +new Date(ticket.createdAt), }); }); }, }); Please note the following changes: - The props now include hubspot instead of github to use HubSpot’s app authentication. - The url in the axios request has been updated to HubSpot’s endpoint for fetching tickets. You might need to adjust this URL based on the specific API endpoint you intend to use and any additional query parameters required for your use case. - The data processing part in the forEach loop has been adjusted to match the structure of HubSpot’s tickets. You’ll need to replace ticket.properties.subject and other properties based on the actual structure of the data returned by HubSpot’s API. This code is a starting point. Depending on your specific requirements, you may need to adjust the API endpoint, request headers, query parameters, and the data processing logic.

in the following code i also need ticket body
import { axios } from “@pipedream/platform”;

export default defineComponent({
name: “HubSpot Tickets Source”,
description: “Fetches HubSpot tickets on a schedule”,
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},
},
// Replace the URL with the endpoint for fetching tickets from HubSpot
url: https://api.hubapi.com/crm/v3/objects/tickets,
});
// Assuming the response structure is an array of tickets
data.forEach((ticket) => {
this.$emit(ticket, {
id: ticket.id,
summary: TICKET ${ticket.id}: ${ticket.properties.subject},
ts: ticket.createdAt && +new Date(ticket.createdAt),
});
});
},
});

To include the ticket body in the emitted events, you’ll need to adjust the summary line within the forEach loop to include the ticket body from the ticket’s properties. Assuming the ticket body is stored under a property named body (you might need to adjust this based on the actual response structure of the HubSpot API), the updated code snippet would look like this: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HubSpot Tickets Source", description: "Fetches HubSpot tickets on a schedule", 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/crm/v3/objects/tickets`, }); // Assuming the response structure is an array of tickets data.forEach((ticket) => { this.$emit(ticket, { id: ticket.id, // Updated to include ticket body. Adjust the property name as needed. summary: `TICKET ${ticket.id}: ${ticket.properties.subject} - Body: ${ticket.properties.body}`, ts: ticket.createdAt && +new Date(ticket.createdAt), }); }); }, }); Please ensure that you replace ticket.properties.body with the correct property path to access the ticket body in the HubSpot API response. If the property name is different, you’ll need to adjust it accordingly.

the following code modify for zendesk tickets:

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 GitHub code for fetching Zendesk tickets, you’ll need to adjust the API endpoint, authentication method, and the data structure according to Zendesk’s API. Here’s how you can adapt the code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "Zendesk Ticket Source", description: "Fetches new tickets from Zendesk on a schedule", props: { zendesk: { type: "app", app: "zendesk", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 * 60, // Checks for new tickets every 15 minutes }, }, }, dedupe: "greatest", async run({ steps, $ }) { const data = await axios($, { method: "get", url: `https://${this.zendesk.$auth.subdomain}.[zendesk.com/api/v2/tickets.json](http://zendesk.com/api/v2/tickets.json)`, headers: { Authorization: `Bearer ${this.zendesk.$auth.oauth_access_token}`, }, }); // Assuming the tickets are in the `tickets` array of the response data.tickets.forEach((ticket) => { this.$emit(ticket, { id: ticket.id, summary: `TICKET ${ticket.id}: ${ticket.subject}`, body: ticket.description, ts: ticket.created_at && +new Date(ticket.created_at), }); }); }, }); This code does the following: - Changes the props to use the Zendesk app. - Modifies the axios call to use Zendesk’s API endpoint for fetching tickets. You’ll need to replace subdomain with your Zendesk subdomain. - Adjusts the data.forEach loop to iterate over tickets returned by Zendesk’s API. The structure of the emitted event is updated to match the expected fields from a Zendesk ticket. Make sure to replace subdomain with your actual Zendesk subdomain in the API URL.