EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

Using MSTR REST APIs to push notifications to Apple Watch


Robert Prochowicz

Manager, Sales Engineering • MicroStrategy


With MSTR APIs you can write a fast and easy solution to notify users when a certain condition is met in a MicroStrategy report. Yes, there is out-of-the-box Alerting capability, but APIs give you much more freedom in building your solution. You can combine analytical power of MicroStrategy with millions of other existing solutions. And you can do it in days and not months of coding.

APIs are a means by which two different programs are able to communicate. APIs enable companies to grow their businesses more quickly by building new solutions in a fraction of time and cost as compared to when APIs are not available. (read more here: https://www.glowtouch.com/importance-apis-business/)
With MSTR APIs you can write a fast and easy solution to notify users when a certain condition is met in a Strategy report. Yes, there is out-of-the-box Alerting capability, but APIs give you much more freedom in building your solution. You can combine analytical power of Strategy with millions of other existing solutions. And you can do it in days and not months of coding.
In my example I want to monitor "AVG Units Requests". I want to be notified immediately when the AVERAGE order contains more than 10 units of a product.
On the video example, initially, I have 5 orders with 5 units ordered in each one - naturally then, the average is 5. I am using Transaction Services to enlarge one order to 65 - the new average is 17. As you see I am almost instantly getting a notification on my Apple Watch (as well as on my iPhone).

ka04W000000ObGKQA0_0EM2R000000hJaD.jpeg

How was it done?
- the main components are powerful APIs delivered by Strategy and Pushover.net
- I am using one of Transaction Services examples in standard Strategy Tutorial project (report and document are modified a little bit)
- I wrote a short and simple Python script - mstrio library is being used
- every 2 seconds the Python script executes a report about orders and checks if 'AVG Units Requested' is bigger than 10
- if the condition is met the value is sent as a message to Pushover.net service and from there to Pushover iPhone and Apple Watch apps (7 days free trial).
PYTHON code


import requests
from mstrio import Strategy
from time import sleep

conn = Strategy.Connection(base_url="http://warw7243.corp.Strategy.com:8080/MicroStrategyLibrary/api", username="mstr", password="XXXXXX", project_name="Strategy Tutorial")
conn.connect()

avg_start=0
mstr_alert=10 #bottom threshold for the average value

for i in range(20):
    print(i)
    report_dataframe = conn.get_report(report_id='81F61B444CCE854A3DAF26841A459E5D')
    avg = report_dataframe.iloc[0]["AVG Units Requested"]
    messagge_mstr = "AVG Units Requested is " + str(avg)

    if avg>mstr_alert and avg_start!=avg:
        r = requests.post("https://api.pushover.net/1/messages.json", data = {
            "token": "ZZZZZZZZZZZZZ",
            "user": "YYYYYYYYYYYYYY",
            "message": messagge_mstr
        })
        print("message sent for AVG: " + str(avg) + " " + r.text)
    sleep(2) #lag time
    avg_start = avg


Comment

0 comments

Details

Example

Published:

June 16, 2019

Last Updated:

June 16, 2019