user-1
(User 1)
September 10, 2023, 3:24pm
1
This topic was automatically generated from Slack. You can find the original thread here .
Hey - why am I getting the error “Request failed with status code 400: $.respond() not called for this invocation” when attempting to post to a pipedream webhook endpoint?
user-1
(User 1)
September 10, 2023, 3:24pm
2
It looks like you’re encountering an error because the respond()
method is not being called in your HTTP-triggered source. To fix this issue, you should use the this.http.respond()
method within the run
method of your source, and also set the customResponse: true
parameter in the http
prop. Here’s an example of how to do this: export default { name: "HTTP Example", version: "0.0.1", props: { http: { type: "$.interface.http", customResponse: true, }, }, async run(event) { this.http.respond({ status: 200, body: { msg: "hello world!", }, headers: { "content-type": "application/json", }, }); console.log(event); }, };
Make sure to include the this.http.respond()
method in your source code to avoid the “Request failed with status code 400: $.respond() not called for this invocation” error.
user-1
(User 1)
September 10, 2023, 3:24pm
3
got it - want to update this code so that it will work with a pipedream workflow’s HTTP trigger?
user-1
(User 1)
September 10, 2023, 3:24pm
4
hey please update this code so that it will work with a pipedream workflow’s HTTP trigger
user-1
(User 1)
September 10, 2023, 3:24pm
5
Sure! Here’s the updated code to work with a Pipedream workflow’s HTTP trigger: ```
export default { name: “HTTP Example”, version: “0.0.1”, props: { http: { type: “$.interface.http”, customResponse: true, }, }, async run(event) { this.http.respond({ status: 200, body: { msg: “hello world!”, }, headers: { “content-type”: “application/json”, }, }); console.log(event); }, };
user-1
(User 1)
September 10, 2023, 3:24pm
6
can you explain to me why the following code is producing the error “$.respond() not called for this invocation”?
import { axios } from “@pipedream /platform”;
export default defineComponent({
name: “HTTP Example”,
version: “0.0.1”,
props: {
http: {
type: “$.interface.http”,
customResponse: true ,
},
},
async run({ steps, $ }) {
const response = await axios($, {
method: “POST”,
url: “https://eok1zwx7y2cz69b.m.pipedream.net ”,
data: {
recipe_extract: steps.trigger.event.body.recipe_extract,
recipe_slug: steps.trigger.event.body.recipe_slug,
recipe_clean_url: steps.trigger.event.body.recipe_clean_url,
recipe_instructions: steps.create_html.$return_value,
},
headers: {
“user-agent”: “pipedream/1”,
“content-type”: “application/json”,
},
});
return $.respond({
status: 200,
body: response.data
});
},
});
user-1
(User 1)
September 10, 2023, 3:24pm
7
I see the issue in your code. You’re using $.respond()
instead of this.http.respond()
. To fix the error, replace $.respond()
with this.http.respond()
. Here’s the corrected code: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HTTP Example", version: "0.0.1", props: { http: { type: "$.interface.http", customResponse: true, }, }, async run({ steps, $ }) { const response = await axios($, { method: "POST", url: "https://eok1zwx7y2cz69b.m.pipedream.net", data: { recipe_extract: steps.trigger.event.body.recipe_extract, recipe_slug: steps.trigger.event.body.recipe_slug, recipe_clean_url: steps.trigger.event.body.recipe_clean_url, recipe_instructions: steps.create_html.$return_value, }, headers: { "user-agent": "pipedream/1", "content-type": "application/json", }, }); this.http.respond({ status: 200, body: response.data }); }, });
Make sure to use this.http.respond()
to avoid the “$.respond() not called for this invocation” error.
user-1
(User 1)
September 10, 2023, 3:24pm
8
this still did not resolve the error - I am still getting “Error - Request failed with status code 400 “$.respond() not called for this invocation””
user-1
(User 1)
September 10, 2023, 3:24pm
9
I apologize for the confusion. Let’s try a different approach to ensure the this.http.respond()
is always called using a try
/ finally
block: import { axios } from "@pipedream/platform"; export default defineComponent({ name: "HTTP Example", version: "0.0.1", props: { http: { type: "$.interface.http", customResponse: true, }, }, async run({ steps, $ }) { try { const response = await axios($, { method: "POST", url: "https://eok1zwx7y2cz69b.m.pipedream.net", data: { recipe_extract: steps.trigger.event.body.recipe_extract, recipe_slug: steps.trigger.event.body.recipe_slug, recipe_clean_url: steps.trigger.event.body.recipe_clean_url, recipe_instructions: steps.create_html.$return_value, }, headers: { "user-agent": "pipedream/1", "content-type": "application/json", }, }); this.http.respond({ status: 200, body: response.data, }); } catch (error) { console.error("Error:", error); this.http.respond({ status: 500, body: { msg: "An error occurred" }, }); } }, });
This code will ensure that this.http.respond()
is always called, even if an error occurs during the execution. If the error persists, please double-check the webhook URL and the data being sent.