Problem
When mocking an API endpoint to respond to a webhook for a Run Task, the callback may return the following error, even if the Callback URL and Access Token are correct.
{
"errors": [
"Not found"
],
"success": false
}Cause
This error can occur if the API request to the callback URL uses an incorrect HTTP method, such as POST. The Run Task callback endpoint expects a PATCH request as specified in the documentation.
Solution
Modify the API request to use the PATCH method.
To test the callback, you can use the following example. First, create a file named payload.json with the task result data.
{
"data": {
"type": "task-results",
"attributes": {
"status": "passed",
"message": "Test"
}
}
}Next, execute the following curl command, ensuring you replace the placeholder URL with the task_result_callback_url value from the Run Task and set the $TOKEN environment variable.
$ curl \ --header "Authorization: Bearer $TOKEN" \ --header "Content-Type: application/vnd.api+json" \ --request PATCH \ --data @payload.json \ https://app.terraform.io/api/v2/task-results/5ea8d46c-2ceb-42cd-83f2-82e54697bddd/callback
Outcome
After sending the request with the correct PATCH method, the Run Task Callback API will respond with a successful 200 status code, and the Run Task will update its status in the HCP Terraform or Terraform Enterprise UI.