This topic was automatically generated from Slack. You can find the original thread here.
With the Slack Integration, what string do I have to use in the blocks property when using send-block-kit-message? I keep getting Error: An API error occurred: invalid_blocks every time.
Your blocks array is valid for Slack in terms of Block Kit structure. Here’s your block: on [ { "type": "section", "text": { "type": "plain_text", "text": "This is a plain text section block.", "emoji": true } } ] This is a valid Slack Block Kit array, and it will render as a section with plain text. However, the error you’re seeing (invalid_blocks) is likely due to how you’re passing the blocks to the Slack API or the Pipedream action. — ## Key Points - Slack expects the blocks property as a JSON array, not a string. - If you pass the blocks as a string (even if it’s a JSON string), Slack will reject it with invalid_blocks. - You should pass the blocks as a native array/object, not as a stringified or URL-encoded value. — ## Example: Correct Usage in Pipedream Code Step Here’s a working example from Pipedream docs: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { slack: { type: "app", app: "slack", }, }, async run({ steps, $ }) { return await axios($, { method: "POST", url: `https://slack.com/api/chat.postMessage`, headers: { Authorization: `Bearer ${this.slack.$auth.oauth_access_token}`, }, data: { channel: "#general", // or your channel/user ID blocks: [ { type: "section", text: { type: "plain_text", text: "This is a plain text section block.", emoji: true, }, }, ], }, }); }, }); — ## If Using a Pipedream Prebuilt Action If you’re using a Pipedream action (like send-block-kit-message), you must pass the blocks as a JSON array, not as a string. If the UI asks for a string, try entering the array directly (not stringified), or use the “Configure” option to build the array. — ## Summary - Your block structure is valid. - Do NOT pass blocks as a string. Pass as a JSON array/object. - If you continue to have issues, please visit Support - Pipedream for more help. Let me know if you need an example for your exact workflow or if you’re using a specific Pipedream action UI!
This is the definition for the prop returned by the SDK:
{
"name": "blocks",
"type": "string",
"label": "Blocks",
"description": "Enter an array of [structured blocks](https://app.slack.com/block-kit-builder) as a URL-encoded string. E.g., `[{ \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"This is a mrkdwn section block :ghost: **this is bold**, and ~this is crossed out~, and <https://pipedream.com|this is a link>\" }}]`\n\n****Tip:**** Construct your blocks in a code step, return them as an array, and then pass the return value to this step."
}
It clearly says “string”.
Anyways, I have tried both approaches: using a string and an array. I have also tested passing the array directly and wrapping it in a JSON object with a blocks attribute. Unfortunately, all combinations have failed.
I’m sorry you’re running into this issue—invalid_blocks is a frustrating error, and I understand how confusing it can be. If you continue to have trouble, please visit Support - Pipedream for more help. Let’s break down the problem and how to resolve it: — ## Why is this happening? - The prop definition you shared expects a string: specifically, a URL-encoded JSON string representing the array of blocks. - If you pass a plain JSON string or a JavaScript array, it will fail. - If you pass a non-URL-encoded string, it may also fail, depending on how the action parses the input. — ## What does the action expect? From the prop description: > Enter an array of structured blocks as a URL-encoded string. > E.g., [{ \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"This is a mrkdwn section block :ghost: **this is bold**, and ~this is crossed out~, and <https://pipedream.com|this is a link>\" }}] So, you need to: 1. Build your blocks as a JS array. 2. Stringify the array with JSON.stringify. 3. URL-encode the string with encodeURIComponent. 4. Pass the result as the string value for the blocks prop. — ## Example: How to do this in a Code Step Add a code step before your Slack action: export default defineComponent({ async run({ steps, $ }) { const blocks = [ { type: "section", text: { type: "plain_text", text: "This is a plain text section block.", emoji: true, }, }, ]; // Stringify and URL-encode return encodeURIComponent(JSON.stringify(blocks)); }, }); Then, in your Slack action’s blocks prop, reference the output of this step: {{steps.YOUR_CODE_STEP_NAME.$return_value}} — ## Common mistakes - Passing a raw array or object: The action expects a string, not an array. - Not URL-encoding: Even a valid JSON string will fail if not URL-encoded. - Malformed JSON: Make sure your blocks array is valid JSON before encoding. — ## If you still see invalid_blocks - Double-check your encoding. - Try with a very simple block (like above). - If possible, test your blocks JSON in the Slack Block Kit Builder to ensure it’s valid. - If nothing works, please reach out at Support - Pipedream with your workflow details. — Again, sorry for the trouble—this is a tricky prop, and you’re not alone in hitting this. If you need more help, please reach out to Support - Pipedream.
Yes, I can help! The error you’re seeing (invalid_blocks) is a common one when sending Block Kit messages to Slack via Pipedream, and it usually means the blocks parameter is not formatted as Slack expects. What’s wrong? - In your code, you’re passing blocks as a JavaScript array directly in configuredProps. - However, most Pipedream Slack actions expect the blocks property as a stringified JSON value (sometimes even URL-encoded), not as a raw array. How to fix: ### 1. Stringify the blocks array Change this: "blocks": [ { "type": "section", "text": { "type": "plain_text", "text": "This is a plain text section block.", "emoji": true } } ], To this: "blocks": JSON.stringify([ { "type": "section", "text": { "type": "plain_text", "text": "This is a plain text section block.", "emoji": true } } ]), ### 2. (If needed) URL-encode the string Some actions require the blocks string to be URL-encoded. If you still get errors after stringifying, try: "blocks": encodeURIComponent(JSON.stringify([ { "type": "section", "text": { "type": "plain_text", "text": "This is a plain text section block.", "emoji": true } } ])), ### 3. Double-check the action’s docs - If you’re using a prebuilt Pipedream Slack action, check the prop description for blocks—it will say if it needs to be URL-encoded. - If you’re using the Slack API directly, it just needs to be a JSON string. — Summary: Always pass blocks as a JSON string (and URL-encode if required). Passing a raw array will cause invalid_blocks. — If you continue to have trouble, please visit Support - Pipedream for more help.
I get that blocks is a dynamic property, that is only available after setting passArrayOrConfigure: "array". But username is also a hidden property only available after setting customizeBotSettings: true, and it works without having to pass a dynamicPropsId…