Hello All,
I'm very new to the work of programming and I am stuck on some code I have written. The code is basically this: I have a CSV of device serial numbers and I want to claim them into our organization. I'm using the Action batches API to do this. When I run the code I have written thus far, I get a 400 response. I'm thinking that my payload is not correct, but it could be anything at this point.
Any help would be appreciated. Thanks.
Code:
# Import os to get api key
import requests
import json
import os
import csv
api_key = os.environ.get("API_KEY")
baseUrl = 'https://dashboard.meraki.com/api/v0/'
action_url = f"{baseUrl}organizations/XXXXXX/actionBatches"
headers = {
'Accept': '*/*',
'Content-Type': 'application/json',
'X-Cisco-Meraki-API-Key': api_key
}
# Open CSV file with serial numbers and print the headers
filename = 'meraki_ap.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
for index, column_header in enumerate(header_row):
print(index, column_header)
# Get serial numbers of devices
serials = []
for row in reader:
serial = str(row[1])
serials.append(serial)
print(serials)
for serial in serials:
payload = """{
"confirmed": true,
"synchronous": false,
"actions": [
{
"resource": "/networks/L_XXXXXXXXXXXXX/devices/",
"operation": "claim",
"body": {
"serial": serial
}
}
]
}"""
claim = requests.post(action_url, headers=headers, data=payload)
print(claim)