API returning 404 on almost all requests

coeIT
Just browsing

API returning 404 on almost all requests

Hi,

 

I made a small Python script in order to manage the network and some of its information.

The script is very simple:

  • it gather the organization ID
  • then, with this ID, it tries to list the administrators

I also tried with HTTP requests such as:

curl -X GET \
  'https://api.meraki.com/api/v0/organizations/<org_id>/admins' \
  -H 'X-Cisco-Meraki-API-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

but the only thing that I can retrieve is the organization name and its ID. All other requests keep failing and are returning 404.

 

I checked my API key and used different methods (Python, curl, postman, etc.) and also different routes: 

https://n123.meraki.com/api/v0

 and

https://api.meraki.com/api/v0

 

Could anyone help me?

 

Thank you for your time.

20 Replies 20
Adam
Kind of a big deal

Sometimes if you use Postman it'll help you refine your queries and do further testing.  I usually use it first before going to code. 

Adam R MS | CISSP, CISM, VCP, MCITP, CCNP, ITILv3, CMNO
If this was helpful click the Kudo button below
If my reply solved your issue, please mark it as a solution.
jdsilva
Kind of a big deal

Can you post the exact code you're using? It's hard to diagnose when we don't know exactly what you're sending (redact api keys naturally).

 

Aslo, this module might make your life easier:

 

https://github.com/meraki/dashboard-api-python

 

 

coeIT
Just browsing

Sure, here is a part of it:

 

from requests import get

url = 'https://api.meraki.com'
api_url = url + '/api/v0'

# different in my code
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
api_header = {
    'X-Cisco-Meraki-API-Key': api_key,
    'Content-Type': 'application/json'
}

# different in my code
org_id = 00_00_00


def rprint(rq):
    if rq.status_code == 404:
        print('** ERROR')
    else:
        print(f'[{rq.status_code}]\t{rq.json()}')


if __name__ == '__main__':
    rprint(get(api_url + f'/organizations', headers=api_header))
    rprint(get(api_url + f'/organizations/{org_id}/admins', headers=api_header))

and it's printing:

[200]	[{'id': XXXXXX, 'name': 'xxxxxxxxxxxxxxxxx'}]
** ERROR

Process finished with exit code 0

I generated another API key, so this one is definitely valid, but I have the same result..

PhilipDAth
Kind of a big deal
Kind of a big deal

I don't know powershell well enough, but perhaps try changing:

rprint(get(api_url + f'/organizations/{org_id}/admins', headers=api_header))

to:

rprint(get(api_url + '/organizations/'+org_id+'/admins', headers=api_header))
coeIT
Just browsing

This is string formatting in Python3.X, already tried in a different way

 

MarkD_BT
Getting noticed

Do a quick test in your browser copy the url and see the results. Does it show what you expect. I find firefox is best for this. Make sure it redirects to the correct shard and you have to be logged into the relevant org to begin with.

https://api.meraki.com/api/v0/organizations/<org_id>/admins
[200]	[{'id': XXXXXX, 'name': 'xxxxxxxxxxxxxxxxx'}]
** ERROR

Process finished with exit code 0

Looks like a 200 'ok' answer so it's accepted but not getting results back. It should have more fields that just id and name also for the results.

MarkD_BT
Getting noticed

Actually the 200 is from the find the org api/v0/organizations so your not getting that result which can't pump it back in to the new url for the admins of that org. Try putting the org id in your script 1st and see if you get admins then you can look at passing results from one url onto another Get request.

PhilipDAth
Kind of a big deal
Kind of a big deal

404 means the URL you are requesting is not valid.  Look at your complete URL closely.

jdsilva
Kind of a big deal
commtech
Comes here often

Hi I am having the same issue and have done everything you have recommended and including looking at Wireshark captures but am also still getting 404 errors! Postman seems to be using TLS v1.2 but I have played with the settings to see if it makes a difference and it doesn't.

 

I simply want to create an SSID via POST in postman... as follows:-

 

https://n194.meraki.com/api/v0/networks/L_672162244385048740/ssids/0

 

I have tried without the shard using https://dashboard.meraki.com and https://api.merkai.com aswell and am asusing these both should in theory work as they will just reditrect the https request ? But neither works.

 

The JSON body part is as follows:- 

 

{
"number":0,
"name":"TEST",
"enabled":true,
"authMode":"psk",
"encryptionMode":"wpa",
"psk":"abcd1234",
"splashPage":"Click-through splash page",
"perClientBandwidthLimitUp":0,
"perClientBandwidthLimitDown":0,
"ssidAdminAccessible":false,
"ipAssignmentMode":"Bridge mode",
"walledGardenEnabled":true,
"walledGardenRanges":"192.168.1.1/24 192.168.37.10/32"
}

 

MarkD_BT
Getting noticed

Is this the 1st api call you have utilised?

 

it might be worth using postman for a simple GET response

 

https://api.meraki.com/api/v0/organizations

 

Is the org you are trying to add the ssid to listed on this GET if yes move down to networks of the org

https://api.meraki.com/api/v0/organizations/{organizationId}/networks

 

I've always found working at the top level then working down to be the best way to find out where the problem is in scripts.

USMC92
Getting noticed

Make sure you're specifying the correct TLS version, try adding this at the top of your script:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

coeIT
Just browsing

I checked with:

from requests import get

if __name__ == '__main__':
    print(get('https://www.howsmyssl.com/a/check').json()['tls_version'])

and it showed me that I am already using TLS 1.2

 

Requests are still failing ..

MarkD_BT
Getting noticed

have you tried rather then

rprint(get(api_url + f'/organizations/{org_id}/admins', headers=api_header))

using

 

rprint(get(https://api.meraki.com/api/v0/organizations/[00_00_00]/admins, headers=api_header))

 

give it all the information you have 1st to see if it works then you can look how to input the strings correctly

coeIT
Just browsing

It still failing..

 

A small test validate that using f formatting or hardcoded string is the same:

if __name__ == '__main__':
    url = 'https://api.meraki.com'
    api_url = url + '/api/v0'
    org_id = 42_42_42

    print(api_url + f'/organizations/{org_id}/admins')
    print('https://api.meraki.com/api/v0/organizations/424242/admins')

output:

https://api.meraki.com/api/v0/organizations/424242/admins
https://api.meraki.com/api/v0/organizations/424242/admins
MarkD_BT
Getting noticed

and if you place that into a browser like firefox

https://api.meraki.com/api/v0/organizations/424242/admins

do you get results back or a blank page?

coeIT
Just browsing

A blank page...

MarkD_BT
Getting noticed

Are you logged into Meraki at the moment log in goto the org in question and access the admins page you are trying to pull back when open goto a new tab and try the api url again on firefox.

 

coeIT
Just browsing

Already tried that, didn't work either..

MarkD_BT
Getting noticed

what rights do you have over the org are you sure you have rights as an admin as it seems you do not which is why you cant access that information.

Get notified when there are additional replies to this discussion.