cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6077
Views
9
Helpful
7
Replies

How to add multiple users by using API

mutsumi3232
Community Member

Hi,

I tried to add some users as "Meraki Auth User" with this page;

https://developer.cisco.com/meraki/api-latest/#!create-network-meraki-auth-user

I got 200, OK, when did via this site, by Meraki Python Library, and Python request template.

But I can't add some users at the SAME time.

Could you tell me some clues?

payload = '''{
    "accountType": "802.1X",
    "email": "xxx@test.com",
    "name": "Test Meraki",
    "password": "secretsecret",
    "emailPasswordToUser": false,
    "isAdmin": false,
    "authorizations": [
        {
            "ssidNumber": 0,
            "expiresAt": "Never"
        }
    ]
}'''
1 Accepted Solution

Accepted Solutions

Andy Mikulas
Level 5
Level 5

Example of untested python script

from meraki import meraki
import json

# Set up the Meraki API key
MERAKI_API_KEY = 'your_api_key_here'
meraki_api = meraki.DashboardAPI(api_key=MERAKI_API_KEY)

# Set up the network ID for which you want to create Meraki Auth users
NETWORK_ID = 'your_network_id_here'

# Define the function to create Meraki Auth users
def create_meraki_auth_user(email, name, password):
    # Set up the payload for the Meraki API call to create the Meraki Auth user
    payload = {
        'email': email,
        'name': name,
        'password': password
    }

    # Make the Meraki API call to create the Meraki Auth user
    try:
        response = meraki_api.networks.createNetworkMerakiAuthUser(NETWORK_ID, payload)
        print(f"Created Meraki Auth user {email}")
    except meraki.APIError as e:
        print(f"Failed to create Meraki Auth user {email}: {e}")

# Read the user list file
with open('user_list.txt', 'r') as file:
    user_list = file.readlines()

# Loop through the user list and create Meraki Auth users
for user in user_list:
    email, name, password = user.strip().split(',')
    create_meraki_auth_user(email, name, password)

View solution in original post

7 Replies 7

Greenberet
Level 8
Level 8

You can only add one user at a time. You would need to create multiple requests.

I haven't tried it with the user endpoint, but you could try action batches

Thank you @Greenberet !!

I've just checked this solution, and am going to try this one.

Andy Mikulas
Level 5
Level 5

Should just be able to accomplish it with a simple loop through a list for each call/user.

Andy Mikulas
Level 5
Level 5

Example of untested python script

from meraki import meraki
import json

# Set up the Meraki API key
MERAKI_API_KEY = 'your_api_key_here'
meraki_api = meraki.DashboardAPI(api_key=MERAKI_API_KEY)

# Set up the network ID for which you want to create Meraki Auth users
NETWORK_ID = 'your_network_id_here'

# Define the function to create Meraki Auth users
def create_meraki_auth_user(email, name, password):
    # Set up the payload for the Meraki API call to create the Meraki Auth user
    payload = {
        'email': email,
        'name': name,
        'password': password
    }

    # Make the Meraki API call to create the Meraki Auth user
    try:
        response = meraki_api.networks.createNetworkMerakiAuthUser(NETWORK_ID, payload)
        print(f"Created Meraki Auth user {email}")
    except meraki.APIError as e:
        print(f"Failed to create Meraki Auth user {email}: {e}")

# Read the user list file
with open('user_list.txt', 'r') as file:
    user_list = file.readlines()

# Loop through the user list and create Meraki Auth users
for user in user_list:
    email, name, password = user.strip().split(',')
    create_meraki_auth_user(email, name, password)

Philip D'Ath
Meraki Community All-Star
Meraki Community All-Star

I would give @Andy Mikulas even more kudos if I could for including a code concept snippit.

Thank you @Andy Mikulas

I tried this with a little arrangement for my environment, but I got an error below;

"Failed to create Meraki Auth user meraki.testmeraki2@test.com: networks, createNetworkMerakiAuthUser - 400 Bad Request, {'errors': ["'email' must be a string"]}"

Thank you again for your kind replies.

Warm Regards.

import meraki
import json

# Set up the Meraki API key
MERAKI_API_KEY = 'My_API_Key'
meraki_api = meraki.DashboardAPI(api_key=MERAKI_API_KEY)

# Set up the network ID for which you want to create Meraki Auth users
NETWORK_ID = 'My_Network_ID'
authorizations = [{'ssidNumber': 0, 'expiresAt': 'Never'}]

# Define the function to create Meraki Auth users
def create_meraki_auth_user(email, name, accountType, password):
    # Set up the payload for the Meraki API call to create the Meraki Auth user
    payload = {
        'email': 'xxxx@test.com',
        'name': 'test meraki1',
        'accountType': '802.1x',
        'password': 'passwordcisco'
    }

    # Make the Meraki API call to create the Meraki Auth user
    try:
        response = meraki_api.networks.createNetworkMerakiAuthUser(NETWORK_ID, [authorizations], payload)
        print(f"Created Meraki Auth user {email}")
    except meraki.APIError as e:
        print(f"Failed to create Meraki Auth user {email}: {e}")

# Read the user list file
with open('user_list.txt', 'r') as file:
    user_list = file.readlines()

# Loop through the user list and create Meraki Auth users
for user in user_list:
    email, name, accountType, password = user.strip().split(',')
    create_meraki_auth_user(email, name, accountType, password)

Not sure, but sounds like the email you are passing is not being sent as a string, Try double quotes around the email address perhaps?

'email' : "xxxx@test.com"

That or the way you added in authorizations isn't passing correctly.

The code sample you posted doesn't appear to match what was used to generate the error.