question

Dan Berkeland avatar image
Dan Berkeland asked ·

Trouble with Python reserved word "from" as API attribute

I want to create a list of phone numbers from my message list using this Python script but am hung up on the 'from' attribute since it is a Python reserved word. Not sure what I am doing wrong. This script results in no numbers.

resp = platform.get('/restapi/v1.0/account/~/extension/~/message-store').json()

messList=resp.records

for i in messList:
    
    try:
      fromMess=getattr(i,'from')
      fromMess=fromMess.phoneNumber

    except:
      fromMess='no number'

    print(fromMess)


api sms
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

· Write an Answer
Dan Berkeland avatar image
Dan Berkeland answered ·

Solved it this way

resp = platform.get('/restapi/v1.0/account/~/extension/~/message-store').json()

messList=resp.records

for i in messList:
    messID=i.id
    
    try:
      fromMess = platform.get('/restapi/v1.0/account/~/extension/~/message-store/'+str(messID))
      fromMess=fromMess.text()
      fromMess=json.loads(fromMess)
      whoMess=fromMess["from"]["phoneNumber"]
      
      print(whoMess)
            
    except:
      print("skipped message")


1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys