├── GetHistoryData ├── GetXMLSchema ├── GetLookupTable - Holiday ├── GetRINList ├── GetHistoricalRINList ├── GetValue ├── GetLookupTable ├── GetToken ├── PostValue └── Registration /GetHistoryData: -------------------------------------------------------------------------------- 1 | def GetHistoryData(token, rateID, startdate, enddate): 2 | 3 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 4 | url = 'http://midasapi.energy.ca.gov/api/historicaldata?id=' + rateID + '&startdate=' + startdate + '&enddate=' + enddate 5 | 6 | list_response = requests.get(url, headers=headers) 7 | return (json.loads(list_response.text)) 8 | -------------------------------------------------------------------------------- /GetXMLSchema: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | #Query passes in JWT access token as "token" 5 | 6 | def GetValue(token): 7 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 8 | url = 'https://midasapi.energy.ca.gov/api/valuedata' 9 | pricing_response = requests.get(url, headers=headers) 10 | 11 | return (json.loads(pricing_response.text)) 12 | -------------------------------------------------------------------------------- /GetLookupTable - Holiday: -------------------------------------------------------------------------------- 1 | def LookupTable(token): 2 | 3 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 4 | url = 'https://midasapi.energy.ca.gov/api/holiday' 5 | 6 | pricing_response = requests.get(url, headers=headers) 7 | response = requests.get(url,headers=headers) 8 | print(response) ##Added to function to get 200 response## 9 | 10 | return (json.loads(pricing_response.text)) 11 | -------------------------------------------------------------------------------- /GetRINList: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | # parameter signaltype acceptable values: 4 | # 0 = All signal types 5 | # 1 = Tariff signals only 6 | # 2 = Green House Gas Emissions only 7 | # 3 = Flex Alerts only 8 | 9 | def GetRINList(token, signaltype): 10 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 11 | url = 'https://midasapi.energy.ca.gov/api/valuedata?signaltype=' + signaltype 12 | list_response = requests.get(url, headers=headers) 13 | return (json.loads(list_response.text)) 14 | -------------------------------------------------------------------------------- /GetHistoricalRINList: -------------------------------------------------------------------------------- 1 | #query passes in JWT access token as "token", distributioncode and energycodes formatted as 2-character strings found in each lookup table 2 | 3 | def GetHistoryRINs(token, DistributionCode, EnergyCode): 4 | 5 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 6 | url = 'http://midasapi.energy.ca.gov/api/historicallist?' + 'DistributionCode=' + DistributionCode + '&EnergyCode=' + EnergyCode 7 | list_response = requests.get(url, headers=headers) 8 | return (json.loads(list_response.text)) 9 | -------------------------------------------------------------------------------- /GetValue: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | #Query passes in JWT access token as "token", Rate Identification Number (RIN) as rateID formatted as a string, and "alldata" or "realtime" for queryType formatted as a string 5 | 6 | def GetValue(token, rateID, queryType): 7 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 8 | url = 'https://midasapi.energy.ca.gov/api/valuedata?id=' + rateID + '&querytype=' + queryType 9 | pricing_response = requests.get(url, headers=headers) 10 | 11 | return (json.loads(pricing_response.text)) 12 | -------------------------------------------------------------------------------- /GetLookupTable: -------------------------------------------------------------------------------- 1 | def LookupTable(token, LookupTable): 2 | headers = {'accept': 'application/json', 'Authorization': "Bearer " + token} 3 | url = 'https://midasapi.energy.ca.gov/api/valuedata?' + 'LookupTable=' + LookupTable 4 | pricing_response = requests.get(url, headers=headers) 5 | response = requests.get(url,headers=headers) 6 | print(response) ##Added to function to get 200 response## 7 | return (json.loads(pricing_response.text)) 8 | 9 | #Lookup Tables: 10 | 11 | #['Country', 'Daytype', 'Distribution', 'Enduse', 'Energy', 'Location', 'Ratetype', 'Sector', 'State', 'TimeZone', 'Unit'] 12 | -------------------------------------------------------------------------------- /GetToken: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import base64 4 | 5 | #Function passes through your MIDAS username and password as strings and returns the JWT token as a string 6 | 7 | def GetToken(username, password): 8 | credentials = username + ":" + password 9 | credentials_encodedBytes = base64.b64encode(credentials.encode("utf-8")) 10 | 11 | headers = {b'Authorization': b'BASIC ' + credentials_encodedBytes} 12 | url = 'https://midasapi.energy.ca.gov/api/token' 13 | 14 | response = requests.get(url,headers=headers) 15 | print(response.text) 16 | 17 | return response.headers['Token'] 18 | -------------------------------------------------------------------------------- /PostValue: -------------------------------------------------------------------------------- 1 | import base64 2 | import requests 3 | import json 4 | import os 5 | import sys 6 | 7 | # Assumes there is a file on the local filesystem that is correctly formatted against the XML schema in this document 8 | def PostValues(token, priceFileName): 9 | 10 | headers = {'accept': 'application/json', 'Content-Type': 'text/xml', 'Authorization': "Bearer " + token} 11 | url = 'https://midasapi.energy.ca.gov/api/ValueData' 12 | priceFile = open(priceFileName) 13 | xml = priceFile.read() 14 | pricing_response = requests.post(url, data=xml, headers=headers) 15 | 16 | return (pricing_response.text) 17 | 18 | # Uses the GetToken implementation from above in this document 19 | token = GetToken('your_username_here','your_password_here') 20 | 21 | # assumes properly formatted file in same directory as this python script 22 | ret = PostValues( token, 'your_midas_post_price_example.xml' ) 23 | 24 | # A response like " Rate Model(s) added to MIDAS system." Should be received 25 | print(ret) 26 | -------------------------------------------------------------------------------- /Registration: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import base64 4 | 5 | ##Encode registration values as base64 6 | 7 | #organization is an optional value in the registration API 8 | organization = "your_org_name" 9 | org_encodedBytes = base64.b64encode(organization.encode("utf-8")) 10 | organization64 = str(org_encodedBytes, "utf-8") 11 | 12 | username = "your_username_here" 13 | user_encodedBytes = base64.b64encode(username.encode("utf-8")) 14 | username64 = str(user_encodedBytes, "utf-8") 15 | 16 | password = "your_password_here" 17 | pswd_encodedBytes = base64.b64encode(password.encode("utf-8")) 18 | password64 = str(pswd_encodedBytes, "utf-8") 19 | 20 | emailaddress = "your_email_here" 21 | email_encodedBytes = base64.b64encode(emailaddress.encode("utf-8")) 22 | emailaddress64 = str(email_encodedBytes, "utf-8") 23 | 24 | fullname = "your_fullname_here" 25 | fullname_encodedBytes = base64.b64encode(fullname.encode("utf-8")) 26 | fullname64 = str(fullname_encodedBytes, "utf-8") 27 | 28 | 29 | #Put together the dict for the JSON payload 30 | registration_info = {"organization":organization64,"username":username64,"password":password64,"emailaddress":emailaddress64,"fullname":fullname64} 31 | 32 | url = 'https://midasapi.energy.ca.gov/api/registration' 33 | headers = {"Content-Type":"application/json"} 34 | 35 | response = requests.post(url, data=json.dumps(registration_info), headers=headers) 36 | 37 | #Prints below will return 200 response for successful call 38 | print(response) 39 | #Response text should be: 'User account for your_user_name was successfully created. A verification email has been sent to your_email. Please click the link in the email in order to start using the API.' 40 | print(response.text) 41 | --------------------------------------------------------------------------------