Can I Develop and Publish Custom Actions/Components in Python Similarly to NodeJS, and How Can It be Done?

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

It is established that i can develop custom actions/components in NodeJS and publish them through the pd CLI, can I do that with Python as well? If so give me an example with code as to how I may accomplish that, and then tell me how I can publish that.

Currently, Pipedream supports publishing custom actions/components using Node.js, but not Python. However, you can still run Python code within your workflows using the “Run Python Code” action. Here’s how to use it: 1. Search for the Python app from the step menu 2. Select the “Run Python Code” action 3. Connect your Python account 4. At the bottom of the step, click Test to run the action and test the configuration. For more details, visit https://pipedream.com/apps/python/actions/run-python-code If you need to create custom actions/components, you’ll need to use Node.js. You can find an example of creating a custom Node.js action and publishing it using the Pipedream CLI in the following documentation: Sharing code across workflows

alright, so help me out with developing custom actions;

How do I use existing source code from Pipedream Actions and edit them slightly to my liking, like for example there is an action that creates a card on a Trello board. I wanna reuse most of the functionality of the action without having to write everything from scratch

You can use the existing Trello “Create Card” action as a starting point and modify it according to your needs. To do this, follow these steps: 1. Add the Trello “Create Card” action to your workflow by searching for the Trello app from the step menu and selecting the “Create Card” action. 2. Connect your Trello account. 3. Configure the required fields (Board, Name, List) and any optional fields you need. If you need to add custom logic or modify the behavior of the action, you can create a custom Node.js code step that uses the Trello API to create a card. Here’s an example of how to make a request to the Trello API to create a card: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { apiKey: { type: “string”, label: “Trello API Key”, }, apiToken: { type: “string”, label: “Trello API Token”, }, boardId: { type: “string”, label: “Board ID”, }, listId: { type: “string”, label: “List ID”, }, cardName: { type: “string”, label: “Card Name”, }, // Add any other required or optional fields here }, async run({ $ }) { const url = “https://api.trello.com/1/cards”; const params = { key: this.apiKey, token: this.apiToken, idBoard: this.boardId, idList: this.listId, name: this.cardName, // Add any other required or optional fields here }; const response = await axios($, { method: “POST”, url, params, }); return response; }, });

do I have to add the keys manually? Can’t I use the OAUTH prop that already exists for trello and other apps to do that for me? This would help me switch accounts and not manually type in the keys each time I wanna do something

You’re right, using OAuth is a better approach for managing Trello API keys and tokens. When you use a pre-built Trello action in Pipedream, the OAuth process is handled automatically. You just need to connect your Trello account, and Pipedream takes care of the rest. However, if you’re creating a custom action using Node.js code, you’ll need to use the Trello API key and token from the connected account. You can access the OAuth access token using this.$auth.oauth_access_token. Here’s an example of how to use the access token in a custom action: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ $ }) { const url = “https://api.trello.com/1/cards”; const params = { key: process.env.TRELLO_API_KEY, // Use your Trello API key token: this.$auth.oauth_access_token, // Use the OAuth access token from the connected account idBoard: “your_board_id”, idList: “your_list_id”, name: “your_card_name”, }; const response = await axios($, { method: “POST”, url, params, }); return response; }, });

why do some actions allow me to edit their code but most do not? For example, the Trello action “search_members” lets me toy around with the action to my liking but “get_card” does not? This inconsistency doesn’t really help me because I want to change any action to add or remove things as I need them.

I understand your concern. The ability to edit the code of some actions and not others is due to the way Pipedream has implemented these actions. Some actions are built using Pipedream’s component code, which allows you to view and edit the code directly, while others are implemented as pre-built actions that cannot be edited. If you need to modify an action that doesn’t allow you to edit its code, you can create a custom action using Node.js code that interacts with the Trello API. You can use the existing editable actions as a starting point or refer to the Trello API documentation for more details on how to make API calls: https://developer.atlassian.com/cloud/trello/guides/rest-api/api-introduction/ Remember to use the OAuth access token from the connected Trello account by accessing this.$auth.oauth_access_token in your custom action. If you need help creating a custom action, please let me know the specific requirements, and I’ll be happy to assist you.