Meraki Camera API Snapshot

BrianKL
Conversationalist

Meraki Camera API Snapshot

Hi,

 

I'm trying to take a snapshot by using the CURL giving the network id, the camera's serial number, and all the necessary data. However, when making the POST of the CURL, I get a 400 error Response.

 

HTTP ERROR 400
Problem accessing /cameras/live_snapshot. Reason:
     can't parse j son parameters: No content to map due to end-of-input

 

I'm not sure what the problem is exactly.

 

Thank You,

11 Replies 11
jdsilva
Kind of a big deal

Can you post the curl command you're using? Be sure to redact your API key, serial and network ID.

BrianKL
Conversationalist

Hi,

 

I'm using Python requests:

 

headers = {
                 'X-Cisco-Meraki-API-Key': API_KEY,
                 'Content-Type': 'application/json',
}

 

response = requests.post('https://api.meraki.com/api/v0/networks/'+NET_ID+'/cameras/'+SERIAL_CAM1+'/snapshot', headers=headers)

jdsilva
Kind of a big deal

It looks like the API doc is wrong. remove the content-type json stuff and it works for me.

 

headers = {
                 'X-Cisco-Meraki-API-Key': API_KEY,
}
requests.post('https://api.meraki.com/api/v0/networks/<netID>/cameras/<serial>/snapshot', headers=headers)

Or

 

curl -L -H 'X-Cisco-Meraki-API-Key: <api_key>' -X POST 'https://api.meraki.com/api/v0/networks/<Net_ID>/cameras/<serial>/snapshot'
BrianKL
Conversationalist

Thank you very much, now it works correctly 😄

jdsilva
Kind of a big deal

Hey @TonyC  @CameronMoody  FYI looks like the API doc for Camera snapshots might have an error in it.

 

https://api.meraki.com/api_docs#generate-a-snapshot-of-what-the-camera-sees-at-the-specified-time-an...

 

Sorry if this isn't you guys, but I thought the API guy and the doc guy would be good places to start 🙂

TonyC
Meraki Employee
Meraki Employee

Thanks for the report, we have reproduced and will address. For now omitting the application-type header appears to address as @jdsilva indicated
Rafaetero
Getting noticed

Hello @TonyC I am trying to fetch the snapshot through code, but there is no possible way, it only works in a browser... Do you have any example?

BrianKL
Conversationalist

I used Python:

 

import requests
import json

API_KEY = 'YOUR_API_KEY'
NET_ID = 'YOUR_NETWORK_ID'
SERIAL_CAM = 'YOUR_CAMERA_SERIAL_NUMBER'

headers = {
                    'X-Cisco-Meraki-API-Key': API_KEY,
}

try:
      response = requests.post('https://api.meraki.com/api/v0/networks/'+NET_ID+'/cameras/'+SERIAL_CAM+'/snapshot', headers=headers)
except requests.exceptions.RequestException as e:
      print("Error: %s" %(e))

data = response.json()
url_link = data['url']
print(url_link)
Rafaetero
Getting noticed

I did it with node , the problem as described here https://community.meraki.com/t5/Solutions-APIs/Snapshot-API-not-working-404/td-p/45294 is that i did need to wait 5 seconds before fetching

Dynamo6
Conversationalist

+1 for this. I have been trying without success with php curl. I have the link url, but cannot retrieve the actual image.

Willem_vd_Pas
Just browsing

After you have the link, request the link.

 


try
:
response = requests.request("POST", urlApi, headers=header, data=payload)
except:
print ('error')
print (response.status_code)

if response.status_code == 202:
urlVideo = response.text
time.sleep(5) # wait 5 sec then the image is availble
dc_data = eval(response.text)
urlVideo = (dc_data['url'])

    resp = requests.request("GET", urlVideo, stream=True)
fn = 'imagename.jpg'
try:
with open(fn, 'wb') as f:
for chunk in resp:
f.write(chunk)
f.close()

 

Get notified when there are additional replies to this discussion.