I am trying to use IBM OpenWhisk. It has its own CLI, but I wanted to invoke a simple "echo" sample using curl.
curl -d-data '{"message": "hellow world"}' https://user:[email protected]:443/api/v1/namespaces/whisk.system/action/samples/echo
curl: (6) Couldn't resolve host '"message": "hello world"'
{
"error": "HTTP method not allowed, supported methods: GET",
"code": 81107
}
How can I invoke it OpenWhisk via curl or similar tools, how do I authenticate?
Authentication is done via Basic Authentication, hence you can use the -u flag in curl. Using the user:pass@url version as you used it should work aswell.
To invoke an action you have to use POST, hence -XPOST. Also, the API expects application/json as the Content-Type. Data is sent via the -d flag in curl.
You also have a typo in your url. You need to use actions instead of action (the whole API uses plurals).
All in all, your request should look like this:
curl -XPOST -H "Content-Type: application/json" -d '{"message": "hello world"}' -u $USERNAME:$PASSWORD https://openwhisk.ng.bluemix.net/api/v1/namespaces/whisk.system/actions/samples/echo
There is a blog article covering this topic. For blocking actions just add ?blocking=true as parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With