ibm-cloudibm-cloud-code-engine

IBM Cloud Code Engine: How to pass non-JSON data in ping subscription?


I am trying to pass some form data to my app from a Code Engine ping subscription. In the create command, I have tried different methods to pass the data as part of the POST request, but it resulted in wrong parameters at runtime when the ping event fired.

  ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
      --schedule '07 4,8,13,17 * * *' --data 'SECRET_KEY=SET_YOUR_SECRET' 
  ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
      --schedule '07 4,8,13,17 * * *' --data '{"SECRET_KEY":"SET_YOUR_SECRET"}' 

How can I pass the data as regular text data, not as JSON?


Solution

  • I took a while to figure it out. The CLI command allows to pass --content-type. In the documentation is the example application/json. For regular data, it would be form data and urlencoded. The following works, i.e., using application/x-www-form-urlencoded:

     ibmcloud ce sub ping create -n tweety --destination twitterbot --path /tweet
         --schedule '07 4,8,13,17 * * *' --data 'SECRET_KEY=SET_YOUR_SECRET' 
         --content-type 'application/x-www-form-urlencoded'