API - Handling dicts and pagination

Solved
RaphaelL
Kind of a big deal
Kind of a big deal

API - Handling dicts and pagination

Hi ,

 

Some recent changes to getOrganizationSwitchPortsStatusesBySwitch have broken my code and pagination.

I don't condider my self great with Python or programmation in general so bear with me.

 

The output is now a dict instead of a list. How do you handle that output when receiving multiple pages ? Dicts were easy , you simply do final_list = final_list + new_list   at every page and it grows into a big list voilà !

 

 

With dicts I can't do that. 

 

Example of the output :

 

{
  "items": [
    {
      "name": "xxxxxxxx",
      "serial": "xxxx",
      "mac": "xxxxx",
      "network": {
        "id": "xxxxxxxxx",
        "name": "xxxxx"
      },
      "model": "MS225-24P",
      "ports": [
        {
          "portId": "1",
          "enabled": true,
          "status": "Connected",
          "isUplink": true,
          "errors": [],
          "warnings": [],
          "speed": "1 Gbps",
          "duplex": "full",
          "securePort": {
            "active": false,
            "authenticationStatus": "Enabled"
          },
          "spanningTree": {
            "statuses": [
              "Forwarding",
              "Is edge",
              "Is peer-to-peer"
            ]
          },
          "poe": {
            "isAllocated": false
          }
        }]
]

 The only "solution" ( which is probably disgusting ) is to get the list of items and put them in a list. 

 

Using the Meraki Python SDK is not an option in my case and I'm not debating why, that's not the point.

 

 

Thanks ! 😊

1 Accepted Solution
Oren
Meraki Employee
Meraki Employee

Hi @RaphaelL,
The getOrganizationSwitchPortsStatusesBySwitch is a beta operation which is going through changes to improve performance. That's for the breaking change part.
Regarding the format, you can easily adjust the code you're using today.

new_list = response['items']

 

Then,

final_list = final_list + new_list

will work as it has before.

 

View solution in original post

3 Replies 3
double_virgule
Getting noticed

Pulling the items out of the dictionary and adding to a list isn't the worst solution, honestly. It depends on what you're wanting to do with it.

Oren
Meraki Employee
Meraki Employee

Hi @RaphaelL,
The getOrganizationSwitchPortsStatusesBySwitch is a beta operation which is going through changes to improve performance. That's for the breaking change part.
Regarding the format, you can easily adjust the code you're using today.

new_list = response['items']

 

Then,

final_list = final_list + new_list

will work as it has before.

 

RaphaelL
Kind of a big deal
Kind of a big deal

Exactly what I did this afternoon. I thought this was a "easy fix" on my end and everytime I do a easy fix it ends up being a dump fix haha !

 

Will it be a "norm" to return the output in a dict with a list "named" items ?

Get notified when there are additional replies to this discussion.