Azure Logic Apps - Consuming
RESTService - Stock Quotes
- Navigate to https://www.alphavantage.co/
- Get your API Key
- Test the connection
https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=GE&interval=1min&apikey=YOURKEY
- Create a new LogicApp
- Add Recurrence as the first shape and configure it to trigger the application every 1 Minute
- Click on the New step -> Add an action
- Then search for Variables
- Initialize a new variable of type string named “LastRefreshed” to store the last refreshed value that provided in the “Meta Data” section of the HTTP response for fetching required data from “Time Series (1min)” section *.
- Initialize another variable (repeat steps 6 and 7) of type float named “value” to store the “Open” value of the given Stock Option
- Add a new action of type HTTP (HTTP - HTTP)
- Specify the GET method in the first filed
- In the lower left corner switch from the Design view to Code View
- At the bottom, you should see the section for parameters
- You need to add the following code inside the brackets
"API": {
"Type": "string",
"defaultValue": "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=XYZ&interval=1min&apikey=YOURKEY"
},
"Symbol": {
"Type": "string",
"defaultValue": "GE"
}
|
- Go back to the Design tab:
- Click inside the Uri field
- In order to make the URI parameterized, click on the Add dynamic content link.
Add the following expression: replace(parameters('API'),'symbolParam',parameters('Symbol'))
- Using LogicApp parameters will make your application more flexible, especially if you would like to query the service for other Stock Options
- Add a new action, search for Variables and then for “Set variable”
- From the drop down, choose LastRefreshed
- Name: LastRefreshed
- Place the cursor in the Value field and click on the Add Dynamic content > Expression
- Expression: body('HTTP')?['Meta Data']['3. Last Refreshed']
- Finally reading values from the latest node of “Time Series (1min)” section, for example we need to get “Open” value and convert it to a float value since the JSON represented as a string, so “float(...)” function will do the job, and the expression for set variable action
- Add the new action: Variables - Set Variable
- Name: value
- Value: Click on the Add dynamic content link and then go to the Expression tab
- Expression: float(body('HTTP')?['Time Series (1min)'][variables('LastRefreshed')]['1. open'])
- Now Deploy the App to azure portal
- Go back to your azure portal and run your application.
- Result
* Initializing Variables actions should be right after the trigger, you can not Initialize variable in the middle of the workflow.
Comments
Post a Comment