Citricguy
Citricguy

Reputation: 421

Using Google Cloud Tasks Using cURL or Without SDK/gcloud

Is it possible to interact with Google services such as Cloud Tasks using nothing more than cURL?

There are several examples for different languages available on the 'create task' section of their API docks, but I don't see anything that does not require the SDK (using cURL for example.)

Ultimately I'm looking to create Cloud Tasks externally without having to include any 3rd party code.

Upvotes: 1

Views: 1565

Answers (2)

Averi Kitsch
Averi Kitsch

Reputation: 921

You can directly call the Cloud Tasks API without using the client libraries.

However, if you are looking for an easy local way to create queues and tasks, I recommend using the Cloud SDK (gcloud CLI tool). This gives you the ability to easily manage your resources without having to roll your own script and authentication. To create an HTTP targetted task:

gcloud tasks create-http-task <TASK_ID_IF_NEEDED> --queue=QUEUE --url=URL

There are additional flags to easily add a header, a scheduled time, a request body, etc.

Upvotes: 0

marian.vladoi
marian.vladoi

Reputation: 8074

You can use Cloud Tasks API to manages the execution of large numbers of distributed requests Cloud Tasks API.

For example to create a new queue called mynewqueue using Method: projects.locations.queues.create you can use :

   curl --request POST \
   'https://cloudtasks.googleapis.com/v2beta3/projects/my- 
    project/locations/europe-west2/queues?key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"name":"projects/my-project/locations/europe-west2/queues/mynewqueue"}' \
 --compressed

where YOUR_ACCESS_TOKEN is the output of :

   gcloud auth print-access-token

and YOUR_API_KEY is optional.

To test if the command was successfull:

   gcloud tasks queues list
   #output mynewqueue   RUNNING  1000              500.0            100

Upvotes: 2

Related Questions