How do I make a M2Web call to get a list of ewons for a particular pool on a PRO account?


#1

How do I make a M2Web call to get a list of ewons for a particular pool on a PRO account?


#2

Hi @anontywdfuin

The following api call will do what you are looking for.

https://m2web.talk2m.com/t2mapi/getewons?t2maccount=account&t2musername=username&t2mpassword=password&t2mdeveloperid=devid&pool=yourpoolname

Note at the end the &pool=poolname parameter. Just update to have your poolname.


#4

Thanks.

Do you have any sample python code to take the reply from this webcall and get the list into some sort of array?


#5

Hi @anontywdfuin

Below is a simple python program that will return a list of all ewons in the defined pool when you call getEwonByPool.

Please note: This code is provided as is

import requests

accountInfo = "https://m2web.talk2m.com/t2mapi/getaccountinfo"
devicesInfo = "https://m2web.talk2m.com/t2mapi/getewons"

account = "Your account"
username = "Your username"
password = "Your password"
developerId = "Your developerId"
poolName = "Pool you want" #This is case sensitive!


# Retrieve the pool id required by the api call based on 
# the pool name. 
# returns int
def getPoolId(name):
    r = requests.post(accountinfo, data={
    't2maccount' : account, 
    't2musername' : username,
    't2mpassword' : password,
    't2mdeveloperid' : developerid
  })

  data = r.json()
  for pool in data['pools']:
      if pool['name'] == name:
          return pool['id']


# Retrieve the eWON list by the pool id
# returns JSON array of eWONs in the pool
def getEwonByPool():
  poolid = getPoolId(poolName)
  r = requests.post(devicesInfo, data={
    't2maccount' : account, 
      't2musername' : username,
      't2mpassword' : password,
      't2mdeveloperid' : developerid,
      'pool' : poolid
  })
  return r.json()


# Test our call
print(getEwonByPool())


I hope this helps!


Repl.it sandbox


#6

Thanks Jordan