Python Delete Org Admin problem

damienleick
Getting noticed

Python Delete Org Admin problem

Hi I encounter a problem for deleting a user with API

 

My code :

##Credentials
MY_API_KEY = 'xxxxxxxxxxxxxxxxxx'
MY_ORG = 'xxxxxxxxxxxxxxxxxxx'

##Inition de la library Meraki
import meraki
import json
import csv
##Inition de l'API
dashboard = meraki.DashboardAPI(
        api_key=MY_API_KEY,
        base_url='https://api-mp.meraki.com/api/v0/',
        #Désactivation/Activation du debug
        print_console=True,
        #Désactivation/Activation du logging
        output_log=False,        
)

##Debut de Script

with open('user_delete.csv''r'as csvfile:
    users = csv.reader(csvfile, delimiter=',')
    next(users)
    for id_user in users:
        dashboard.admins.deleteOrganizationAdmin(MY_ORG, id_user)

 

 

 

 

reponse code :

 

 

Admins, deleteOrganizationAdmin - 404 Not Found,
Traceback (most recent call last):
File "delete_user.py", line 34, in <module>
dashboard.admins.deleteOrganizationAdmin(MY_ORG, id_user)
File "C:\Program Files (x86)\Python 3\lib\site-packages\meraki\api\admins.py", line 97, in deleteOrganizationAdmin
return self._session.delete(metadata, resource)
File "C:\Program Files (x86)\Python 3\lib\site-packages\meraki\rest_session.py", line 232, in delete
self.request(metadata, 'DELETE', url)
File "C:\Program Files (x86)\Python 3\lib\site-packages\meraki\rest_session.py", line 153, in request
raise APIError(metadata, response)
meraki.exceptions.APIError: Admins, deleteOrganizationAdmin - 404 Not Found,

C:\inetpub\wwwroot\merakidevops\script\Admin creation\Create Agent V3.0\Move and change\Delete>pause

6 REPLIES 6
Nash
Kind of a big deal

You're getting a 404, which means bad URL - resource not found.

 

Are you able to run dashboard.organizations.getOrganizations() using the same parameters?

What happens if you remove base_url?

@Nash  

 

If I remove the base URL i have the same error  (i have multiple script who have this base url and they work with no problem)

 

 

The GetOrganization work

 

 

Nash
Kind of a big deal


@damienleick wrote:

@Nash  

 

If I remove the base URL i have the same error  (i have multiple script who have this base url and they work with no problem)

 

 

The GetOrganization work

 

 


Okay cool, so the base works. That makes life easier!

 

Here's how I'd tshoot this:

 

  1. Does getOrganizationAdmins work as expected? I.E. your org num is good?
  2. If you run that for loop and print(id_user) instead of del admin, do you see the admin IDs you expect to see?
  3. If you get admin IDs that match admins in getOrganizationAdmin, try running with a try-except structure. I messed with Postman: if you have an admin ID that doesn't match an admin in the org, you also get a 404 error. 

 

What if you do a try-except like:

 

with open('user_delete.csv', 'r') as csvfile:
    users = csv.reader(csvfile, delimiter=',')
    next(users)
    for id_user in users:
        try:
            dashboard.admins.deleteOrganizationAdmin(MY_ORG, id_user)
        except:
            print(f"No admin {id_user} found.")

 

If that works, do go back and clean up that except so it's not a blanket exception... This is quick and dirty.

PhilipDAth
Kind of a big deal
Kind of a big deal

Where did you get the id_user values from?

Edgar-VO
Building a reputation

From the .csv file which he is reading

Nash
Kind of a big deal


@Edgar-VO wrote:

From the .csv file which he is reading


Okay, where did you get the data that you've put into the CSV file?

Get notified when there are additional replies to this discussion.