I'm trying to use Google Cloud Tasks, creating a task via "Try this API" web feature or the Ruby Google Cloud SDK.
I can't get the payload to be delivered to a worker.
Sending the Http Method as POST actually works, but shows up as GET in the Cloud Tasks UI.
No payload or headers are sent to the worker or shows up in the Cloud Task UI. I've tried Base64, JSON, normal strings. (see images below)
Example:
Request:
{
"task": {
"httpRequest": {
"httpMethod": "POST",
"body": "SGVsbG8=",
"url": "https://some-random-url"
}
}
}
Response:
{
"name": "projects/<my-project>/locations/europe-west1/queues/default/tasks/73572672049866200001",
"scheduleTime": "2019-07-03T14:49:34.450453Z",
"createTime": "2019-07-03T14:49:34Z",
"view": "BASIC",
"httpRequest": {
"url": "https://some-random-url/",
"httpMethod": "POST",
"headers": {
"User-Agent": "Google-Cloud-Tasks"
}
},
"dispatchDeadline": "600s"
}
Example Ruby code:
task = {
http_request: {
url: <project/location/queue/url>,
http_method: 'POST',
body: "Something"
}
}
response = @client.create_task(@parent, task)
Screenshots from Google Cloud UI:
Is there some special format to set a payload to be delivered via POST ?
Thank you!
Thank You for this post, this is a bug in the existing Cloud Tasks UI and we are in the process of fixing this bug.
In the meantime the correct HTTP method of the task can be determined by running the following command:
gcloud beta tasks describe
https://cloud.google.com/sdk/gcloud/reference/beta/tasks/describe
The above command will show the correct HTTP method for the task.
Answer from: Google Cloud Tasks always set HttpMethod to GET when using HttpRequest as payload_type
You can also use the get task method to get more information.
Thank you. After seeing this I actually figured out I was wrong about the payload part. It is in fact being delivered regardless of what is shown in the Google Tasks UI so it is just a visual bug.
@JoseGoncalves when you use
gcloud beta tasks describe
did you see the body? I tried to use that to check for the task, the method is POST but there is nobody
field too. From my target I also cannot find the body. I'm using@google-cloud/tasks 1.2.0
npm module. Not sure if you can see the body too.You can also use the client library's method GetTaskRequest with response view of 'FULL' to view the body. Make sure you have the correct permissions to access the info.