redirects from api.meraki.com sockets

SOLVED
Andrewbluepiano
Getting noticed

redirects from api.meraki.com sockets

Hi team. 

Bit of an odd question. Using sockets to send my GET's, and if I send it directly to https://api.meraki.com it redirects to n151.meraki.com.

 

All well and good, I just followed the redirect and used that GET as my reference.

 

My question is if the API's all go through n151, or if I will really need to parse that initial response to the reply from https://api.meraki.com for the correct node. This is intended for anyone to be able to use, not just myself. 

1 ACCEPTED SOLUTION
Nash
Kind of a big deal

Each org has a shard it's on, right? api.meraki.com attempts to identify the shard for your organization, then redirects to the correct shard. In this case, n151.

 

If you want to know the shard for a specific organization, you can use Get Organizations and then trim the org['url'] kinda like this. I'm using Python. Try running this in a Python shell.

 

Then you can just pass that to your request statement instead of api.meraki.com. Can speed things up a little...

 

 

org = {"id": "random", "name": "Test", "url": "https://n263.meraki.com/gibberish"}

print(f"Original URL: {org['url']}")
urlLength = org['url'].find('com') + 3
orgShard = org['url'][8:urlLength]

print(f"Trimmed shard URL: {orgShard}")

 

View solution in original post

9 REPLIES 9
Nash
Kind of a big deal

Each org has a shard it's on, right? api.meraki.com attempts to identify the shard for your organization, then redirects to the correct shard. In this case, n151.

 

If you want to know the shard for a specific organization, you can use Get Organizations and then trim the org['url'] kinda like this. I'm using Python. Try running this in a Python shell.

 

Then you can just pass that to your request statement instead of api.meraki.com. Can speed things up a little...

 

 

org = {"id": "random", "name": "Test", "url": "https://n263.meraki.com/gibberish"}

print(f"Original URL: {org['url']}")
urlLength = org['url'].find('com') + 3
orgShard = org['url'][8:urlLength]

print(f"Trimmed shard URL: {orgShard}")

 

Nash,

So if I send this 

 

GET /api/v0/networks/NETWORKNUM/clients HTTP/1.1
Host: api.meraki.com
Accept: application/json
x-cisco-meraki-api-key: keyhere
Content-Length: 15

timespan=1800

 

 

to  https://api.meraki.com, I get back

 

 

<html><body>You are being <a href="https://n151.meraki.com/api/v0/networks/NETWORKNUM/clients">redirected</a>.</body></html>

 

 

Just wanted to confirm that it changes based on the customers shard, which is sounds like is the case, and wasn't just n151 for all API stuff. Thanks for the clarification!

 

~Andrew Afonso~

Strongly recommend you scrub that network number that you've included. That's why my example just said gibberish. 🙂

Oof. Thought about that, but I thought the only confidential part was the API key. How dangerous is publishing the network num (Just want to know if I need to go searching if I've done it anywhere else). 

To me it's all keys. Keys should be private, even if you need multiple keys in order to complete a transaction.

PhilipDAth
Kind of a big deal
Kind of a big deal

This is a great example of why I have been promoting the use of dotenv, and for the complete removal of API keys and sensitive information from code.

 

https://community.meraki.com/t5/Developers-APIs/A-newer-safer-way-to-access-the-dashboard-API/m-p/69... 

There is a new beta API service called "Mega Proxy" that does not use redirects.  You can try it out using api-mp.meraki.com instead of api.meraki.com.

Lololol. Literally just finished & published the project I was asking for. But I may add that in. Can anyone just use the api-mp?

>Can anyone just use the api-mp?

 

Yes.

Get notified when there are additional replies to this discussion.