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

Creating Subscriptions with multiple attachments using REST API


Robert Prochowicz

Manager, Sales Engineering • MicroStrategy


With MicroStrategy 2021, it is possible to use REST API to create subscriptions. Even better, it is possible to add multiple attachments to such subscriptions. This is a long anticipated improvement to the platform.

Creating Subscriptions with multiple attachments using REST API
Since Strategy 2021 it is possible to use REST API to create subscriptions. Even better, it is possible to add multiple attachments to such subscriptions. This is a long anticipated improvement to the platform.
Python script below is based on plain string format of request body. It is also possible to use just mstrio module (mstrio 11.3 !) which should further simplify the script. More details about mstrio.admin.subscription package you can find here: https://www2.Strategy.com/producthelp/2020/mstrio-py/mstrio.admin.subscription.html
Please note - I've added color formatting in the code below (http://hilite.me/). Code copied from here might not work due to indentation issues. In that case, use attached file with sample code.
 


# Robert Prochowicz / 2020-12-31
# tested on MSTR 11.3
# This script creates a new subscription with multiple (!) attachments
 
from datetime import datetime
from mstrio.connection import Connection
 
#### Parameters ####
api_login = 'administrator'
api_password = ''
base_url = 'http ://MSTR-SERVER/MicroStrategyLibrary/'
project_id = 'B7CA92F04B9FAE8D941C3E9B7E0CD754'

### FUNCTIONS
def postSubscription(connection, project_id, headers, data):
    r = connection.session.post(url=connection.base_url + "/api/subscriptions", headers=headers, data=data)
    if r.ok:
        print("Error: " + str(r.raise_for_status()) + "   ||   HTTP Status Code: " + str(r.status_code))
    else:
        print("HTTP %i - %s, Message %s" % (r.status_code, r.reason, r.text))

### REST Parameters
headers = {"X-MSTR-ProjectID" : project_id,
           'Content-Type':'application/json','Accept':'application/json'}

json_long='''{
  "name": "aa_json_long",
  "allowDeliveryChanges": false,
  "allowPersonalizationChanges": false,
  "allowUnsubscribe": false,
  "sendNow": true,
  "owner": {
    "id": "54F3D26011D2896560009A8E67019608"
  },
  "schedules": [
    {
      "id": "FF7BB3B311D501F0C00051916B98494F"
    }
  ],
  "contents": [
    {
      "id": "C89B5E5D4E0E8EF1E622FDAC873FAA2C",
      "type": "document",
      "personalization": {
        "formatMode": "DEFAULT",
        "viewMode": "DEFAULT",
        "formatType": "PDF",
        "exportToPdfSettings": {
          "pageOption": "PAGE",
          "pageSize": "letter",
          "orientation": "auto",
          "pageDetailLevel": "overview",
          "includeToc": false,
          "includeHeader": true,
          "includeFooter": true,
          "filterSummary": "BAR",
          "fitToPage": false,
          "repeatColumnHeader": false,
          "gridPagingMode": "none"
        }
      }
    },
    {
      "id": "77C0F2614D81B7A0C636628B2AC748CE",
      "type": "report",
      "personalization": {
        "formatMode": "DEFAULT",
        "viewMode": "DEFAULT",
        "formatType": "EXCEL"
      }
    }	
  ],
  "recipients": [
    {
      "id": "0FAEA06701784CA38C729B866F1110B6",
      "type": "personal_address",
      "includeType": "TO"
    }
  ],
  "delivery": {
    "mode": "EMAIL",
    "expiration": "2020-12-29T10:13:04.486Z",
    "contactSecurity": true,
    "email": {
      "subject": "string",
      "message": "<HTML>Yello!<BR><H1>ROBERT</H1></HTML>",
      "sendContentAs": "data",
      "overwriteOlderVersion": true
    }
  }
}'''

json_short = '{\"name\":\"aa_json_short\",\"allowDeliveryChanges\":false,\"allowPersonalizationChanges\":false,\"allowUnsubscribe\":false,\"sendNow\":true,\"owner\":{\"id\":\"54F3D26011D2896560009A8E67019608\"},\"schedules\":[{\"id\":\"FF7BB3B311D501F0C00051916B98494F\"}],\"contents\":[{\"id\":\"C89B5E5D4E0E8EF1E622FDAC873FAA2C\",\"type\":\"document\",\"personalization\":{\"formatMode\":\"DEFAULT\",\"viewMode\":\"DEFAULT\",\"formatType\":\"PDF\",\"exportToPdfSettings\":{\"pageOption\":\"PAGE\",\"pageSize\":\"letter\",\"orientation\":\"auto\",\"pageDetailLevel\":\"overview\",\"includeToc\":false,\"includeHeader\":true,\"includeFooter\":true,\"filterSummary\":\"BAR\",\"fitToPage\":false,\"repeatColumnHeader\":false,\"gridPagingMode\":\"none\"}}},{\"id\":\"77C0F2614D81B7A0C636628B2AC748CE\",\"type\":\"report\",\"personalization\":{\"formatMode\":\"DEFAULT\",\"viewMode\":\"DEFAULT\",\"formatType\":\"EXCEL\"}}],\"recipients\":[{\"id\":\"0FAEA06701784CA38C729B866F1110B6\",\"type\":\"personal_address\",\"includeType\":\"TO\"}],\"delivery\":{\"mode\":\"EMAIL\",\"expiration\":\"2020-12-29T10:13:04.486Z\",\"contactSecurity\":true,\"email\":{\"subject\":\"string\",\"message\":\"<HTML>Yello!<BR><H1>ROBERT</H1></HTML>\",\"sendContentAs\":\"data\",\"overwriteOlderVersion\":true}}}'


conn = Connection(base_url,api_login,api_password)

postSubscription(conn, project_id, headers, json_long)
postSubscription(conn, project_id, headers, json_short)


Comment

0 comments

Details

Example

Published:

December 31, 2020

Last Updated:

November 21, 2022