Pass a variable to the data input

We now have a data input that retrieves information about the YHOO stock symbol every 30 seconds. However, if we wanted information about other stock symbols, we'd need to create a separate data input for each symbol. Rather than hardcode individual stock symbols, we can pass a variable to the REST URL that will enable the user of this add-on to configure the stock symbols they want.

To indicate a variable, we will use the format ${variable_name}. The current REST URL is:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20
(%22YHOO%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=

We'll replace the "YHOO" stock symbol with a variable "${Symbol}" as follows:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20
(%22${Symbol}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=

Now to add a variable field and update the REST URL in our data input.

  1. On the Configure Data Collection page, click Edit for the StockInfo data input.
  2. The Edit Data Input wizard opens.

  3. Click the Data Input Variables tab.
  4. Use this page to define variables for the data input. For this input, we need to define a variable for the stock symbol.

  5. Under Component Library, drag and drop a Text Field to the Data Input Variables pane.
  6. With this field selected, fill out the properties for it on the Property Editor pane:

    • Display Label: Enter "Stock symbol".
    • Internal Name: Enter "Symbol", which is our variable_name.
    • Hints & Help: Enter "Enter a stock symbol"
    • Mandatory: Select this option because the variable is required.

  7. Click Next.
  8. in the REST URL field, replace the value with:
    https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22${Symbol}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
  9. Notice that a new field is displayed for the stock symbol input we defined earlier.

  10. In Stock symbol (Symbol), enter a temporary value for testing, such as "SPLK". You can use any stock symbol you want.
  11. Click Test to verify the REST URL works.
  12. Click Save, and then click Finish.

>>  Continue to Extract fields.