1

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:password@openwhisk.ng.bluemix.net: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?

data_henrik
  • 16,724
  • 2
  • 28
  • 49

3 Answers3

7

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.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
markusthoemmes
  • 3,080
  • 14
  • 23
4

The wsk CLI has also the very handy "-v" option which shows you the HTTP request and headers so if you do:

wsk -v action invoke hello --blocking

you'll see the actual REST API call.

Frederic Lavigne
  • 704
  • 3
  • 12
0

Authentication is done via Basic Authentication. Add an HTTP Header for 'Authorization'. Use the string

'Basic'+base64Encoded(username+':'+password)

where base64Encoded(str) is a method to base64 encrypt a string.

You can find the username and password for your OpenWhisk account on Bluemix via https://console.ng.bluemix.net/openwhisk/learn/cli or via wsk cli: wsk property get it contains the 'whisk auth' property which is in the format 'username:password'

remkohdev
  • 250
  • 3
  • 13