Enhance and record data

  1. 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);

  2. Close the Configuration pane.
  3. Drag an invoke policy action after the gatewayscript.
  4. Set the invoke title to Create WWatcher Report. Then, set the URL to the Cloudant API. This is a URL similar to https://api-key.cloudant.com/weatherwatchers. See the following example:
  5. Scroll down and enter the API key in the Basic Authentication Username field.
  6. Enter the API key secret in the Basic Authentication Password field.
  7. Close the Configuration pane and save your changes.
  8. Click the Test arrow. Then, click Republish product.
  9. Select the post /report operation and enter a sample report.
  10. Scroll down and click Invoke. Notice that the new record is inserted into the Cloudant database.
  11. Scroll up and select the get /report operation.
  12. Scroll down and click Invoke.
    Notice the database contains both records that you created.