News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Trouble with Python reserved word "from" as API attribute
Tags: api sms
Oct 28, 2020 at 12:27pm   •   1 replies  •  0 likes
Dan Berkeland

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)


1 Answer
answered on Oct 28, 2020 at 3:30pm  

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")



 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us