Enhance and record data
- Drag a gatewayscript policy action onto the line after the Get Forecast invoke. Enter the following code. The comment block is optional.
var input = apim.getvariable('request.body');
input.forecast = apim.getvariable('message.body')[0].narrative;
input.fcst_min_temp = apim.getvariable('message.body')[0].min_temp;
input.fcst_max_temp = apim.getvariable('message.body')[0].max_temp;
apim.setvariable('message.body', input);
- Close the Configuration pane.
- Drag an invoke policy action after the gatewayscript.
- Set the invoke title to
Create WWatcher Report
. Then, set the URL to theCloudant API
. This is a URL similar tohttps://api-key.cloudant.com/weatherwatchers
. See the following example:
- Scroll down and enter the API key in the Basic Authentication Username field.
- Enter the API key secret in the Basic Authentication Password field.
- Close the Configuration pane and save your changes.
- Click the Test arrow. Then, click Republish product.
- Select the post /report operation and enter a sample report.
- Scroll down and click Invoke. Notice that the new record is inserted into the Cloudant database.
- Scroll up and select the get /report operation.
- Scroll down and click Invoke.
Notice the database contains both records that you created.