Webtask

Documentation

Parameterizing Webtask Code

URL query parameters are propagated to webtask code

For customized documentation and ready to run samples, please log in.

You can pass paramaters to the webtask code using URL query string of the webtask request. All URL query parameters except the reserved ones (e.g. key) will be propagated to the webtask code when it runs. To take advantage of this feature, define your JavaScript function such that it accepts two arguments instead of one: the context and the callback, e.g:

module.exports = function(context, callback) {
  callback(null, "Hello, " + context.data.name);
}        

All allowed URL query parameters of the webtask request will be provided to the webtask code in the form of context.data JavaScript object.

You can try it out with curl as follows:

curl https://webtask.it.auth0.com/api/run/{webtask_container}?name=Tomek -H "Authorization: Bearer {webtask_token}" --data-binary 'module.exports = function(context, cb) { cb(null, "Hello, " + context.data.name); }'

The option of parameterizing webtask code with URL query parameters is particularly useful when the webtask code is supplied indirectly using the webtask_url, since it usually means the webtask code changes infrequently and independently of the act of issuing a webtask request itself.