Skip to content

Instantly share code, notes, and snippets.

@jasonk
Last active September 17, 2024 20:34
Show Gist options
  • Save jasonk/4772d1cd5154069cfc9eed07acb2057a to your computer and use it in GitHub Desktop.
Save jasonk/4772d1cd5154069cfc9eed07acb2057a to your computer and use it in GitHub Desktop.
Simple Bash Examples for Reolink API
#!/bin/bash
HOST="$REOLINK_NVR_HOST" # Your NVR or Camera IP Address
USER="$REOLINK_NVR_USER" # Your username
PASS="$REOLINK_NVR_PASS" # Your password
# Set this to true and the script will dump the request/response
# payloads to stderr.
DEBUG=false
### END OF CONFIGURATION ###
URL="https://$HOST/cgi-bin/api.cgi"
# TOKEN must initially be set to null, so that it gets passed to the
# login command as `?cmd=Login&token=null`
TOKEN="null"
# Takes an API command as the first argument, and JSON-ish payload as
# an optional second argument. If a payload is provided it's
# processed with `jq -n` to make it easier (jq -n doesn't require
# property names to be quoted, you can have trailing commas and other
# stuff that isn't actually valid JSON)
rl-api() {
local CMD="$1" PARAM='{}'
if [ -n "$2" ]; then PARAM="$(jq -n "$2")"; fi
local REQ="$(
jq -n --arg CMD "$CMD" --argjson PARAM "$PARAM" '{
cmd: $CMD,
action: 0,
param: $PARAM,
}'
)"
local TGT="$URL?cmd=$CMD&token=$TOKEN"
if $DEBUG; then
echo ">>> REQUEST >>>" 1>&2
echo "TARGET: $TGT" 1>&2
jq -C . <<<"$REQ" 1>&2
fi
local RES="$(
curl -kfsSLH 'Content-Type: application/json' -d "[$REQ]" -XPOST "$TGT" |
jq '.[0]'
)"
if $DEBUG; then
echo "<<< RESPONSE <<<" 1>&2
jq -C . <<<"$RES" 1>&2
fi
# If the response had "code: 0" then it was successful, otherwise it
# was an error
if [ "$(jq -r '.code' <<<"$RES")" -eq "0" ]; then
jq '.value' <<<"$RES"
return 0
else
echo -n "$CMD ERROR: " 1>&2
jq -r '"\(.error.detail) (\(.error.rspCode))"' <<< "$RES" 1>&2
return 1
fi
}
# Send a Login command to the API
rl-login() {
rl-api Login "$(
jq -n --arg USER "$USER" --arg PASS "$PASS" '{
User: { userName: $USER, password: $PASS }
}'
)" | jq -r '.Token.name'
}
# Send a Logout command to the API
rl-logout() {
if [ "$TOKEN" = "null" ] || [ "$TOKEN" = "" ]; then return; fi
rl-api Logout > /dev/null
}
# Login with username and password and get a session token
TOKEN="$(rl-login)"
if [ -z "$TOKEN" ]; then exit 1; fi
# Now that we have a token, we add an exit hook to remove it when the
# script exits, if you leave it around you may get the dreaded (and
# annoying) "max session" error. If that happens all you can really
# do is wait, by default the tokens are good for an hour (and the
# session limit is global, so using multiple usernames won't help)
trap 'rl-logout' EXIT
# Process any arguments on the command line as commands, if the
# command is followed by something that looks like a payload, then
# pass that as the payload to the command.
while (( $# )); do
CMD="$1" ; shift
#if (( $# )) && jq -eR 'try(fromjson)' <<<"$1"; then
if (( $# )) && [[ $1 == *[{}]* ]]; then
PAYLOAD="$1" ; shift
else
PAYLOAD="{}"
fi
rl-api "$CMD" "$PAYLOAD" || exit 1
done

List all of your cameras, nicely formatted

./rl-api GetChannelStatus |
  jq -r '.status[] | [.channel,.online,.typeInfo,.name] | @tsv' |
  column -t -s $'\t'

Get abilities for currently logged in user

./rl-api GetAbility '{User:{userName:""}}'

Get abilitiies for specific user

./rl-api GetAbility '{User:{userName:"admin"}}'

Some other useful commands

./rl-api GetDevInfo
./rl-api GetDevName
./rl-api GetTime
./rl-api GetAutoMaint
./rl-api GetHddInfo
./rl-api GetAutoUpgrade
./rl-api GetChannelStatus
./rl-api GetUser
./rl-api GetOnline
./rl-api GetLocalLink
./rl-api GetDdns
./rl-api GetEmail
./rl-api GetFtp
./rl-api GetNtp
./rl-api GetNetPort
./rl-api GetUpnp
./rl-api GetWifi
@mnpg
Copy link

mnpg commented Apr 23, 2023

Instead of adding more reply messages with another examples, I regroup them on my github repo > Folder Bash-scripts

@pixeldoc2000
Copy link

@mnpg awesome examples, nicely documented, thanx!

@pixeldoc2000
Copy link

pixeldoc2000 commented Apr 28, 2023

Just for kicks, here is GetAbility Result for Reolink TrackMix POE with Firmware: v3.0.0.1817_23022700

./rl-api GetAbility '{User:{userName:""}}'
{
  "Ability": {
    "3g": {
      "permit": 0,
      "ver": 0
    },
    "abilityChn": [
      {
        "aiTrack": {
          "permit": 6,
          "ver": 1
        },
        "aiTrackDogCat": {
          "permit": 6,
          "ver": 1
        },
        "alarmAudio": {
          "permit": 6,
          "ver": 1
        },
        "alarmIoIn": {
          "permit": 0,
          "ver": 0
        },
        "alarmIoOut": {
          "permit": 0,
          "ver": 0
        },
        "alarmMd": {
          "permit": 6,
          "ver": 1
        },
        "alarmRf": {
          "permit": 0,
          "ver": 0
        },
        "batAnalysis": {
          "permit": 0,
          "ver": 0
        },
        "battery": {
          "permit": 0,
          "ver": 0
        },
        "cameraMode": {
          "permit": 6,
          "ver": 0
        },
        "disableAutoFocus": {
          "permit": 0,
          "ver": 0
        },
        "enc": {
          "permit": 6,
          "ver": 1
        },
        "floodLight": {
          "permit": 0,
          "ver": 0
        },
        "ftp": {
          "permit": 6,
          "ver": 6
        },
        "image": {
          "permit": 6,
          "ver": 1
        },
        "indicatorLight": {
          "permit": 0,
          "ver": 0
        },
        "isp": {
          "permit": 6,
          "ver": 1
        },
        "isp3Dnr": {
          "permit": 0,
          "ver": 0
        },
        "ispAntiFlick": {
          "permit": 6,
          "ver": 1
        },
        "ispBackLight": {
          "permit": 0,
          "ver": 0
        },
        "ispBright": {
          "permit": 6,
          "ver": 1
        },
        "ispContrast": {
          "permit": 6,
          "ver": 1
        },
        "ispDayNight": {
          "permit": 6,
          "ver": 1
        },
        "ispExposureMode": {
          "permit": 0,
          "ver": 0
        },
        "ispFlip": {
          "permit": 6,
          "ver": 1
        },
        "ispHue": {
          "permit": 0,
          "ver": 0
        },
        "ispMirror": {
          "permit": 6,
          "ver": 1
        },
        "ispSatruation": {
          "permit": 6,
          "ver": 1
        },
        "ispSharpen": {
          "permit": 6,
          "ver": 1
        },
        "ispWhiteBalance": {
          "permit": 6,
          "ver": 0
        },
        "ledControl": {
          "permit": 6,
          "ver": 1
        },
        "live": {
          "permit": 4,
          "ver": 2
        },
        "mainEncType": {
          "permit": 0,
          "ver": 1
        },
        "mask": {
          "permit": 6,
          "ver": 1
        },
        "mdTriggerAudio": {
          "permit": 0,
          "ver": 0
        },
        "mdTriggerRecord": {
          "permit": 0,
          "ver": 0
        },
        "mdWithPir": {
          "permit": 0,
          "ver": 0
        },
        "osd": {
          "permit": 6,
          "ver": 1
        },
        "powerLed": {
          "permit": 0,
          "ver": 0
        },
        "ptzCtrl": {
          "permit": 7,
          "ver": 2
        },
        "ptzDirection": {
          "permit": 1,
          "ver": 1
        },
        "ptzPatrol": {
          "permit": 7,
          "ver": 0
        },
        "ptzPreset": {
          "permit": 7,
          "ver": 1
        },
        "ptzTattern": {
          "permit": 7,
          "ver": 0
        },
        "ptzType": {
          "permit": 0,
          "ver": 3
        },
        "recCfg": {
          "permit": 6,
          "ver": 1
        },
        "recDownload": {
          "permit": 6,
          "ver": 1
        },
        "recReplay": {
          "permit": 6,
          "ver": 1
        },
        "recSchedule": {
          "permit": 6,
          "ver": 2
        },
        "shelterCfg": {
          "permit": 6,
          "ver": 1
        },
        "snap": {
          "permit": 6,
          "ver": 1
        },
        "supportAIDenoise": {
          "permit": 6,
          "ver": 1
        },
        "supportAITrackLimit": {
          "permit": 6,
          "ver": 1
        },
        "supportAITrackSchedule": {
          "permit": 6,
          "ver": 1
        },
        "supportAi": {
          "permit": 6,
          "ver": 1
        },
        "supportAiAnimal": {
          "permit": 0,
          "ver": 0
        },
        "supportAiDetectConfig": {
          "permit": 6,
          "ver": 1
        },
        "supportAiDogCat": {
          "permit": 6,
          "ver": 1
        },
        "supportAiFace": {
          "permit": 0,
          "ver": 0
        },
        "supportAiPeople": {
          "permit": 6,
          "ver": 1
        },
        "supportAiSensitivity": {
          "permit": 6,
          "ver": 1
        },
        "supportAiStayTime": {
          "permit": 6,
          "ver": 1
        },
        "supportAiTargetSize": {
          "permit": 6,
          "ver": 1
        },
        "supportAiTrackClassify": {
          "permit": 6,
          "ver": 1
        },
        "supportAiVehicle": {
          "permit": 6,
          "ver": 1
        },
        "supportAoAdjust": {
          "permit": 0,
          "ver": 1
        },
        "supportAutoTrackStream": {
          "permit": 6,
          "ver": 1
        },
        "supportDigitalZoom": {
          "permit": 0,
          "ver": 1
        },
        "supportFLBrightness": {
          "permit": 6,
          "ver": 1
        },
        "supportFLIntelligent": {
          "permit": 6,
          "ver": 1
        },
        "supportFLKeepOn": {
          "permit": 0,
          "ver": 0
        },
        "supportFLSchedule": {
          "permit": 6,
          "ver": 1
        },
        "supportFLswitch": {
          "permit": 6,
          "ver": 1
        },
        "supportFocus": {
          "permit": 0,
          "ver": 0
        },
        "supportGop": {
          "permit": 0,
          "ver": 1
        },
        "supportGuardPointImage": {
          "permit": 0,
          "ver": 1
        },
        "supportImportExportImage": {
          "permit": 0,
          "ver": 1
        },
        "supportMd": {
          "permit": 6,
          "ver": 1
        },
        "supportPt": {
          "permit": 0,
          "ver": 1
        },
        "supportPtzCalibration": {
          "permit": 0,
          "ver": 1
        },
        "supportPtzCheck": {
          "permit": 6,
          "ver": 0
        },
        "supportPtzPresetImage": {
          "permit": 0,
          "ver": 1
        },
        "supportPtzSpeed": {
          "permit": 0,
          "ver": 1
        },
        "supportThresholdAdjust": {
          "permit": 6,
          "ver": 1
        },
        "supportWhiteDark": {
          "permit": 6,
          "ver": 1
        },
        "supportZoom": {
          "permit": 0,
          "ver": 1
        },
        "supportZoomAndFocusSliderCfg": {
          "permit": 0,
          "ver": 1
        },
        "videoClip": {
          "permit": 0,
          "ver": 0
        },
        "waterMark": {
          "permit": 6,
          "ver": 1
        },
        "white_balance": {
          "permit": 6,
          "ver": 0
        }
      }
    ],
    "alarmAudio": {
      "permit": 6,
      "ver": 1
    },
    "alarmDisconnet": {
      "permit": 6,
      "ver": 1
    },
    "alarmHddErr": {
      "permit": 6,
      "ver": 1
    },
    "alarmHddFull": {
      "permit": 6,
      "ver": 1
    },
    "alarmIpConflict": {
      "permit": 6,
      "ver": 1
    },
    "auth": {
      "permit": 6,
      "ver": 1
    },
    "autoMaint": {
      "permit": 6,
      "ver": 1
    },
    "cloudStorage": {
      "permit": 0,
      "ver": 0
    },
    "customAudio": {
      "permit": 1,
      "ver": 1
    },
    "dateFormat": {
      "permit": 6,
      "ver": 1
    },
    "ddns": {
      "permit": 6,
      "ver": 9
    },
    "ddnsCfg": {
      "permit": 6,
      "ver": 1
    },
    "devInfo": {
      "permit": 4,
      "ver": 1
    },
    "devName": {
      "permit": 6,
      "ver": 2
    },
    "disableAutoFocus": {
      "permit": 0,
      "ver": 0
    },
    "disk": {
      "permit": 0,
      "ver": 0
    },
    "display": {
      "permit": 6,
      "ver": 1
    },
    "email": {
      "permit": 6,
      "ver": 3
    },
    "emailInterval": {
      "permit": 6,
      "ver": 1
    },
    "emailSchedule": {
      "permit": 6,
      "ver": 1
    },
    "exportCfg": {
      "permit": 4,
      "ver": 0
    },
    "ftpAutoDir": {
      "permit": 6,
      "ver": 1
    },
    "ftpExtStream": {
      "permit": 0,
      "ver": 0
    },
    "ftpPic": {
      "permit": 0,
      "ver": 0
    },
    "ftpSubStream": {
      "permit": 6,
      "ver": 1
    },
    "ftpTest": {
      "permit": 6,
      "ver": 0
    },
    "hourFmt": {
      "permit": 6,
      "ver": 2
    },
    "http": {
      "permit": 6,
      "ver": 3
    },
    "httpFlv": {
      "permit": 6,
      "ver": 1
    },
    "https": {
      "permit": 6,
      "ver": 3
    },
    "importCfg": {
      "permit": 1,
      "ver": 0
    },
    "ipcManager": {
      "permit": 6,
      "ver": 1
    },
    "ledControl": {
      "permit": 7,
      "ver": 1
    },
    "localLink": {
      "permit": 6,
      "ver": 1
    },
    "log": {
      "permit": 6,
      "ver": 1
    },
    "mediaPort": {
      "permit": 6,
      "ver": 1
    },
    "ntp": {
      "permit": 6,
      "ver": 1
    },
    "online": {
      "permit": 6,
      "ver": 1
    },
    "onvif": {
      "permit": 6,
      "ver": 3
    },
    "p2p": {
      "permit": 6,
      "ver": 1
    },
    "performance": {
      "permit": 4,
      "ver": 1
    },
    "pppoe": {
      "permit": 6,
      "ver": 0
    },
    "push": {
      "permit": 6,
      "ver": 1
    },
    "pushSchedule": {
      "permit": 6,
      "ver": 1
    },
    "reboot": {
      "permit": 1,
      "ver": 1
    },
    "recExtensionTimeList": {
      "permit": 6,
      "ver": 1
    },
    "recOverWrite": {
      "permit": 6,
      "ver": 1
    },
    "recPackDuration": {
      "permit": 6,
      "ver": 0
    },
    "recPreRecord": {
      "permit": 6,
      "ver": 1
    },
    "restore": {
      "permit": 1,
      "ver": 1
    },
    "rtmp": {
      "permit": 6,
      "ver": 3
    },
    "rtsp": {
      "permit": 6,
      "ver": 3
    },
    "scheduleVersion": {
      "permit": 6,
      "ver": 1
    },
    "sdCard": {
      "permit": 6,
      "ver": 1
    },
    "showQrCode": {
      "permit": 6,
      "ver": 0
    },
    "simMoudule": {
      "permit": 6,
      "ver": 0
    },
    "supportAudioAlarm": {
      "permit": 6,
      "ver": 1
    },
    "supportAudioAlarmEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportAudioAlarmSchedule": {
      "permit": 6,
      "ver": 1
    },
    "supportAudioAlarmTaskEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportBuzzer": {
      "permit": 0,
      "ver": 0
    },
    "supportBuzzerEnable": {
      "permit": 0,
      "ver": 0
    },
    "supportBuzzerTask": {
      "permit": 0,
      "ver": 0
    },
    "supportBuzzerTaskEnable": {
      "permit": 0,
      "ver": 0
    },
    "supportEmailEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportEmailTaskEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpCoverPicture": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpCoverVideo": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpDirYM": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpPicCaptureMode": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpPicResoCustom": {
      "permit": 6,
      "ver": 0
    },
    "supportFtpPictureSwap": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpTask": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpTaskEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpVideoSwap": {
      "permit": 6,
      "ver": 1
    },
    "supportFtpsEncrypt": {
      "permit": 6,
      "ver": 1
    },
    "supportHttpEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportHttpsEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportOnvifEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportPushInterval": {
      "permit": 6,
      "ver": 1
    },
    "supportRecScheduleEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportRecordEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportRtmpEnable": {
      "permit": 6,
      "ver": 1
    },
    "supportRtspEnable": {
      "permit": 6,
      "ver": 1
    },
    "talk": {
      "permit": 4,
      "ver": 1
    },
    "time": {
      "permit": 6,
      "ver": 2
    },
    "tvSystem": {
      "permit": 6,
      "ver": 0
    },
    "upgrade": {
      "permit": 1,
      "ver": 2
    },
    "upnp": {
      "permit": 6,
      "ver": 1
    },
    "user": {
      "permit": 6,
      "ver": 1
    },
    "videoClip": {
      "permit": 0,
      "ver": 0
    },
    "wifi": {
      "permit": 0,
      "ver": 0
    },
    "wifiTest": {
      "permit": 6,
      "ver": 0
    }
  }
}

@mnpg
Copy link

mnpg commented May 5, 2023

Hi @pixeldoc2000, can you confirm that the examples work fine with your camera.
waiting for your answer
Regards

@pixeldoc2000
Copy link

pixeldoc2000 commented May 25, 2023

@mnpg I am using it to change between different PTZ Presets for Day and Night.

Hi @pixeldoc2000, can you confirm that the examples work fine with your camera.

Which examples do you mean? Everything i posted works with Reolink TrackMix PoE.

@mnpg
Copy link

mnpg commented May 25, 2023

@pixeldoc2000

I am using it to change between differenz PTZ Presets for Day and Night

I understand the way you use the PTZ Presets

Which examples do you mean? Everything i posted works with Reolink TrackMix PoE.

I'm talking about the examples i've create (detection zones or privacy masks). Did they work for your TrackMix?

@Jens1966a
Copy link

I guess a basic question, $REOLINK_NVR_HOST, I have three Reolink cameras behind a fixed IP address, 213.X.X.122, the reolink app however shows under System - User Management IP address 83.X.X.182 for all three cameras. I seem not to be able to connect, which HOST address do I use, is it the the local IP or some reolink managed address?

@mnpg
Copy link

mnpg commented Mar 27, 2024

I guess a basic question, $REOLINK_NVR_HOST, I have three Reolink cameras behind a fixed IP address, 213.X.X.122, the reolink app however shows under System - User Management IP address 83.X.X.182 for all three cameras. I seem not to be able to connect, which HOST address do I use, is it the the local IP or some reolink managed address?

Hi @Jens1966a, if your cameras are behind a NVR, change the channel number of your camera in the commands (with the same IP of your NVR) to see if these commands are understood and functional for a particular camera (channel:3 for example). Sorry, I can't test myself to verify if it's working, i 'ain't got a NVR

@Jens1966a
Copy link

Jens1966a commented Mar 27, 2024 via email

@4920441
Copy link

4920441 commented Apr 21, 2024

Hi,
is there any way to download the stored mp4 files from the sd card from a reolink camera by an api call?

there is also running an ftp server on the cam, but I wasn't able to login...maybe thats the easier way for that purpose?

@Jens1966a
Copy link

Jens1966a commented Apr 21, 2024 via email

@4920441
Copy link

4920441 commented Apr 21, 2024

Since I don't wanna use android, ios nor windows, I am stuck with that, I guess? no way to get the stored pics and videos on another way by the provided api or something?

P.S.: who/what is vulkan? the graphic subsystem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment