Can You Provide a Step-by-Step NodeJS Code for Posting a Message to the Basecamp API Using Props?

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

can you write a nodejs code step that posts a message to basecamp api using props

Sure, here’s a Node.js code step that posts a message to Basecamp using props. This example uses the Create Campfire Message action: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { basecamp: { type: “app”, app: “basecamp”, }, accountId: { type: “string”, label: “Account ID”, }, projectId: { type: “string”, label: “Project ID”, }, campfireId: { type: “string”, label: “Campfire ID”, }, content: { type: “string”, label: “Content”, }, }, async run({ $ }) { const url = https://3.basecampapi.com/${this.accountId}/buckets/${this.projectId}/chats/${this.campfireId}/lines.json; const headers = { Authorization: Bearer ${this.basecamp.$auth.oauth_access_token}, “Content-Type”: “application/json”, }; const data = { content: this.content, }; return await axios($, { method: “POST”, url, headers, data, }); }, });

Can you amend as I want to post a message to a project

To post a message to a project in Basecamp, you can use the “Create Message” action. Here’s how to use it in your Pipedream workflow: 1. Search for the Basecamp app from the step menu. 2. Select the “Create Message” action. 3. Connect your Basecamp account. 4. Select an Account ID or pass a string from a previous step. 5. Select a Project ID or pass a string from a previous step. 6. Select a Message Board ID or pass a string from a previous step. 7. Select a Subject or pass a string from a previous step. You can also configure optional fields like Content and Message Types. Once you’ve set up the action, click “Test” at the bottom of the step to test the configuration.

can you create a nodejs code for this rather than using the prebuilt action?

Sure, here’s a Node.js code step to create a message in a Basecamp project: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { basecamp: { type: “app”, app: “basecamp”, }, accountId: { type: “string”, label: “Account ID”, }, projectId: { type: “string”, label: “Project ID”, }, messageBoardId: { type: “string”, label: “Message Board ID”, }, subject: { type: “string”, label: “Subject”, }, content: { type: “string”, label: “Content”, optional: true, }, }, async run({ $ }) { const url = https://3.basecampapi.com/${this.accountId}/buckets/${this.projectId}/message_boards/${this.messageBoardId}/messages.json; const headers = { Authorization: Bearer ${this.basecamp.$auth.oauth_access_token}, “Content-Type”: “application/json”, }; const data = { subject: this.subject, content: this.content, }; return await axios($, { method: “POST”, url, headers, data, }); }, });