How to Modify the Given Code to Retrieve Zendesk Tickets?

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

the following code, modify it to get 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},
ts: issue.created_at && +new Date(issue.created_at),
});
});
},
};

To modify the provided code to get Zendesk tickets instead of GitHub issues, you need to make the following changes: 1. Change the github prop to zendesk. 2. Update the authorization header to use the Zendesk OAuth token. 3. Update the URL to point to the Zendesk API endpoint for tickets. Here is the modified code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "Source Demo", description: "This is a demo source", props: { zendesk: { type: "app", app: "zendesk", }, timer: { type: "$.interface.timer", default: { intervalSeconds: 15 ** 60, }, }, }, dedupe: "greatest", async run({ steps, $ }) { const data = await axios($, { method: "get", headers: { Authorization: `Bearer ${this.zendesk.$auth.oauth_access_token}`, }, url: `https://${this.zendesk.$auth.subdomain}.[zendesk.com/api/v2/tickets](http://zendesk.com/api/v2/tickets)`, }); data.tickets.forEach((ticket) => { this.$emit(ticket, { id: ticket.id, summary: `TICKET ${ticket.id}: ${ticket.subject}`, ts: ticket.created_at && +new Date(ticket.created_at), }); }); }, }); ### Explanation: 1. Props Update: Changed github to zendesk to use the Zendesk app. 2. Authorization Header: Updated to use this.zendesk.$auth.oauth_access_token. 3. URL Update: Changed the URL to https://${this.zendesk.$auth.subdomain}.[zendesk.com/api/v2/tickets](http://zendesk.com/api/v2/tickets) to fetch tickets from Zendesk. 4. *Data Handling: Updated the data handling to iterate over data.tickets and emit each ticket. This code will now fetch tickets from Zendesk every 15 minutes and emit them.

@U05A7KLNALC the following code , modify it ot get posts from a particular subreddit:

the following code :

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

export default defineComponent({
name: “velora-github-issues-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 issues for a user repo, with 15-minute timer intervals.”,
props: {
github: {
type: “app”,
app: “github”,
},
timer: {
type: “$.interface.timer”,
default: {
intervalSeconds: 15 * 60,
},
},
repo_full_name: {
type: “string”,
label: “Repository Full Name”,
description:
“Enter the name of the GitHub repository in the format ‘owner/repo’”,
},
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”,
},
workflow_id: {
type: “string”,
label: “Workspace ID”,
description: “Enter the Workspace ID”,
},
},
dedupe: “greatest”,
async run({ steps, $ }) {
try {
// Step 1: 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},
});

  // Extract the GitHub access token from the response
  const github_token = nangoResponse.credentials.access_token;

  // Step 2: Use the GitHub token to make a request to the GitHub API
  const data = await axios($, {
    method: "get",
    headers: {
      Authorization: `Bearer ${github_token}`,
    },
    url: `https://api.github.com/repos/${this.repo_full_name}/issues`,
  });

  // Step 3: Emit each issue as an event
  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),
      workflow_id: this.workflow_id,
    });
  });
} catch (error) {
  // Handle errors gracefully
  $.error(`Failed to fetch issues: ${error.message}`);
}

},
})

To modify the given code to fetch posts from a particular subreddit instead of GitHub issues, you need to change the API endpoint and adjust the relevant parts of the code. Here’s the modified code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "velora-reddit-posts-source-GET", description: "This is a custom source for Velora AI, which fetches posts from a particular subreddit, with 15-minute timer intervals.", props: { timer: { type: "$.interface.timer", default: { intervalSeconds: 15 ** 60, }, }, subreddit: { type: "string", label: "Subreddit", description: "Enter the name of the subreddit (without 'r/')", }, }, dedupe: "greatest", async run({ steps, $ }) { try { // Step 1: Make a request to the Reddit API to fetch posts from the specified subreddit const data = await axios($, { method: "get", url: `https://www.reddit.com/r/${this.subreddit}/new.json`, }); // Step 2: Emit each post as an event data.data.children.forEach((post) => { this.$emit(post.data, { id: post.data.id, summary: `POST ${post.data.id}: ${post.data.title}`, body: post.data.selftext, ts: post.data.created_utc && +new Date(post.data.created_utc ** 1000), }); }); } catch (error) { // Handle errors gracefully $.error(`Failed to fetch posts: ${error.message}`); } }, }); ### Changes Made: 1. Removed GitHub and Nango props: Since we are fetching posts from Reddit, we no longer need the GitHub and Nango-related props. 2. Added subreddit prop: This allows the user to specify the subreddit they want to fetch posts from. 3. Updated the API request: Changed the URL to fetch posts from the specified subreddit using Reddit’s API. 4. Adjusted the data extraction and emission: Modified the code to handle the structure of Reddit’s API response. This code will fetch new posts from the specified subreddit every 15 minutes and emit each