- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extracting date from API
I need to add an expiry date to self signed guest accounts on the Meraki cloud authentication portal. I am using the "PUT/networks/{networkId}/merakiAuthUsers/{merakiAuthUserId}"
This returns
"name": "Miles Meraki", "password": "secret", "emailPasswordToUser": false, "authorizations": [ { "ssidNumber": 1, "expiresAt": "never" I need to change this to a date and time
"
The authorizations is a list but but it only appears to have 1 index 0
I can find no way to extract the "expiresAt" dictionary value. My Tests in PyCharm
import datetime
import json
import itertools
from datetime import date
from datetime import datetime
from datetime import timedelta
MerakiUser = {
"name": "Russell Sage",
"password:": "Test123",
"emailPasswordToUser": False,
"authorizations" : [
{
"ssidNumber": 1,
"expiresAt": "never"
}
]
}
name = MerakiUser["name"]
print(name)
expiryDate = MerakiUser["authorizations"]
print(expiryDate)
print(type(expiryDate))
print(expiryDate.pop(1))
Traceback (most recent call last):
Dictionary.py", line 23, in <module>
print(expiryDate.pop(1))
IndexError: pop index out of range
Russell Sage
[{'ssidNumber': 1, 'expiresAt': 'never'}]
<class 'list'>
Process finished with exit code 1
Any assistance greatly received
Solved! Go to solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can try this:
MerakiUser["authorizations"][0]["expiresAt"] = "2024-01-19T07:34:33Z" # replace with your desired expiry date
Please, if this post was useful, leave your kudos and mark it as solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can try this:
MerakiUser["authorizations"][0]["expiresAt"] = "2024-01-19T07:34:33Z" # replace with your desired expiry date
Please, if this post was useful, leave your kudos and mark it as solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have literally just worked that out for myself. I have spent hours on this. Grrrrr. Thank you for you confirmation
