-
I am trying to implement the "search" call in PHP.
My quick hack code is:<?php // Login ============================== $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"cmd":"Login","param":{"User":{"userName":"admin","password":"password"}}}]' ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://192.168.1.1/cgi-bin/api.cgi?cmd=Login"); $output = curl_exec($ch); $jsonobj = substr($output,1,-2); $obj = json_decode($jsonobj); echo "Token: ".$obj->value->Token->name."<br>"; $tokenName = $obj->value->Token->name; // Login ============================== $toSearch = '[{ "cmd": "Search", "action":0, "param": { "Search": { "channel": 0, "onlyStatus": 1, "streamType": "main", "StartTime": { "year": 2023, "mon": 04, "day": 21, "hour": 12, "min": 26, "sec": 1 }, "EndTime": { "year": 2023, "mon": 04, "day": 24, "hour": 12, "min": 34, "sec": 1 }]'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://192.168.1.1/api.cgi?cmd=Search&token=".$tokenName); curl_setopt($ch, CURLOPT_POSTFIELDS, $toSearch ); $output = curl_exec($ch); echo $output; ?>
Response is:
Token: 423e78c93350582 [ { "cmd" : "Search", "code" : 1, "error" : { "detail" : "please login first", "rspCode" : -6 } } ]
Other calls seem to work fine.
Any Ideas?
Cam is a Reolink TrackMix WiFi with latest firmware.Reply QuoteShare0- Share this Post
-
copy the link
Copied!
-
@user_686576360607949_686576360607949 Enable HTTPS from Network menu and run the following curl command. Just replace the CameraIP with the private IP of the camera.
curl -s -k -X POST -H "Content-Type : application/json" -d "[{"cmd": "Search", "action":0, "param": { "Search": { "channel": 0, "onlyStatus": 1, "streamType": "main", "StartTime": { "year": 2023, "mon": 04, "day": 21, "hour": 12, "min": 26, "sec": 1},"EndTime": { "year": 2023,"mon": 04, "day": 21, "hour": 21, "min": 34, "sec": 1}}}}]" "https://CameraIP/cgi-bin/api.cgi?user=#username#&password=#password#" -
@joseph-chircop_497308027822318 so do you think using a token is not supported? It is described in the API spec, though.
-
@user_686576360607949_686576360607949 I just finished a long meeting with my engineers and just executed the command and hereunder find the outcome (onlystatus=1 and if you want each detection then onlystatus=0...you have the timestamp and filename). Yes, with the token it should work too.
-
I get the same response with plain curl from my Raspberry Pi. I issued the exact command as suggested. It does not work with http or https and also I get the same result with onlyStatus = 0 or 1
pi@raspberrypi:~ $ curl -s -k -X POST -H "Content-Type : application/json" -d "[{"cmd": "Search", "action":0, "param": { "Search": { "channel": 0, "onlyStatus": 1, "streamType": "main", "StartTime": { "year": 2023, "mon": 04, "day": 21, "hour": 12, "min": 26, "sec": 1},"EndTime": { "year": 2023,"mon": 04, "day": 21, "hour": 21, "min": 34, "sec": 1}}}}]" "https://ip/cgi-bin/api.cgi?user=xxx&password=yyy" [ { "cmd" : "Unknown", "code" : 1, "error" : { "detail" : "please login first", "rspCode" : -6 } } ]
-
PS I think I got it. Played around with the quotation and
pi@raspberrypi:~ $ curl -s -k -X POST -H 'Content-Type : application/json' -d '[{"cmd": "Search", "action":0, "param": { "Search": { "channel": 1, "onlyStatus": 0, "streamType": "main", "StartTime": { "year": 2023, "mon": 04, "day": 25, "hour": 0, "min": 26, "sec": 1},"EndTime": { "year": 2023,"mon": 04, "day": 25, "hour": 21, "min": 34, "sec": 1}}}}]' 'https://ip/cgi-bin/api.cgi?cmd=Search&user=xxx&password=yyy'
seems to be working. Thanks for your patience
-
@user_686576360607949_686576360607949 I ran it on a Linux machine. If Windows you need to insert the escape character / before the " Very simple :). Of course that it should work...ha ha ha
Enjoy PHP..........but I prefer C++
API call "Search" returns "please login first"
-
I am trying to implement the "search" call in PHP.
My quick hack code is:<?php // Login ============================== $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"cmd":"Login","param":{"User":{"userName":"admin","password":"password"}}}]' ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://192.168.1.1/cgi-bin/api.cgi?cmd=Login"); $output = curl_exec($ch); $jsonobj = substr($output,1,-2); $obj = json_decode($jsonobj); echo "Token: ".$obj->value->Token->name."<br>"; $tokenName = $obj->value->Token->name; // Login ============================== $toSearch = '[{ "cmd": "Search", "action":0, "param": { "Search": { "channel": 0, "onlyStatus": 1, "streamType": "main", "StartTime": { "year": 2023, "mon": 04, "day": 21, "hour": 12, "min": 26, "sec": 1 }, "EndTime": { "year": 2023, "mon": 04, "day": 24, "hour": 12, "min": 34, "sec": 1 }]'; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://192.168.1.1/api.cgi?cmd=Search&token=".$tokenName); curl_setopt($ch, CURLOPT_POSTFIELDS, $toSearch ); $output = curl_exec($ch); echo $output; ?>
Response is:
Token: 423e78c93350582 [ { "cmd" : "Search", "code" : 1, "error" : { "detail" : "please login first", "rspCode" : -6 } } ]
Other calls seem to work fine.
Any Ideas?
Cam is a Reolink TrackMix WiFi with latest firmware.
All Categories