Difference between revisions of "Onvif Device Reference Design/Getting Started/REST API"
Khernandez (talk | contribs) (→Supported requests) |
m |
||
(27 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
− | {{Onvif_Device_Reference_Design/Head|previous=Getting Started/Evaluating the Project|next=Getting Started/Purchasing a License| | + | {{Onvif_Device_Reference_Design/Head|previous=Getting Started/Evaluating the Project using Docker|next=Getting Started/Purchasing a License|metakeywords=}} |
</noinclude> | </noinclude> | ||
+ | {{DISPLAYTITLE:ONVIF Device Reference Design - REST API|noerror}} | ||
− | = Introduction = | + | == Introduction == |
− | This project provides a REST API that can be used to access different capabilities of the device. This allows you to modify, for example, configurations, sources and encoders by using REST requests. | + | This project provides a REST API that can be used to access different capabilities of the device. This allows you to modify, for example, configurations, sources, and encoders by using REST requests. |
− | = Important considerations = | + | == Important considerations == |
* We are using Flask as an example of implementations for testing purposes, for commercial implementations, or an implementation exposed to the public, you need to use a server suited for deployment. | * We are using Flask as an example of implementations for testing purposes, for commercial implementations, or an implementation exposed to the public, you need to use a server suited for deployment. | ||
* The OpenSSL keys used are an example of an OpenSSL implementation, and they should be treated like that, for a final implementation we recommend generating or creating your own keys. | * The OpenSSL keys used are an example of an OpenSSL implementation, and they should be treated like that, for a final implementation we recommend generating or creating your own keys. | ||
− | = Supported requests = | + | == Supported requests == |
− | As previously | + | As previously mentioned, this project offers a REST API, these are the current supported requests. |
− | == | + | ===Resources=== |
− | === | + | ====/device-information ==== |
Gets the information of the device. | Gets the information of the device. | ||
− | + | Content type: JSON | |
− | + | {| class="wikitable" | |
− | + | !colspan="3"|GET | |
− | + | |- | |
− | + | |'''Field name''' | |
− | + | |'''Type''' | |
− | + | |'''Description''' | |
− | + | |- | |
− | + | |firmware | |
− | + | |string | |
− | + | |Device Firmware Version | |
− | + | |- | |
+ | |serial_number | ||
+ | |string | ||
+ | |Device Serial Number | ||
+ | |- | ||
+ | |hardware_id | ||
+ | |string | ||
+ | |Device Hardware ID | ||
+ | |- | ||
+ | |model | ||
+ | |string | ||
+ | |Device Model | ||
+ | |- | ||
+ | |manufacturer | ||
+ | |string | ||
+ | |Device Manufacturer | ||
+ | |} | ||
Example: | Example: | ||
+ | |||
+ | <pre> | ||
+ | GET /device-information | ||
+ | </pre> | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 45: | Line 66: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | ====/sources/video==== |
Get the information of all the video sources. | Get the information of all the video sources. | ||
+ | Content type: JSON | ||
− | Type | + | {| class="wikitable" |
+ | !colspan="3"|GET/PUT | ||
+ | |- | ||
+ | |'''Field name''' | ||
+ | |'''Type''' | ||
+ | |'''Description''' | ||
+ | |- | ||
+ | |name | ||
+ | |string | ||
+ | |Video Source name | ||
+ | |- | ||
+ | |enabled | ||
+ | |int | ||
+ | |1 enabled, 0 disabled | ||
+ | |} | ||
− | |||
− | + | Examples: | |
− | + | <pre> | |
− | + | GET /sources/video | |
− | + | </pre> | |
− | + | <pre> | |
− | + | PUT /sources/video | |
− | + | </pre> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 79: | Line 106: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | ====/encoders/video==== |
Get the information of all the video encoders | Get the information of all the video encoders | ||
− | + | Content type: JSON | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | {| class="wikitable" | |
− | + | !colspan="3"|GET/PUT | |
+ | |- | ||
+ | |'''Field name''' | ||
+ | |'''Type''' | ||
+ | |'''Description''' | ||
+ | |- | ||
+ | |name | ||
+ | |string | ||
+ | |Video Encoder name | ||
+ | |- | ||
+ | |enabled | ||
+ | |int | ||
+ | |1 enabled, 0 disabled | ||
+ | |} | ||
− | + | Examples: | |
− | |||
− | + | <pre> | |
− | + | GET /encoders/video | |
− | + | </pre> | |
− | + | <pre> | |
+ | PUT /encoders/video | ||
+ | </pre> | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 114: | Line 148: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ====/configurations/sources/video==== | |
− | |||
− | |||
− | |||
− | === | ||
Get information of all the video source configurations | Get information of all the video source configurations | ||
+ | Content type: JSON | ||
− | Type of | + | {| class="wikitable" |
− | + | !colspan="3"|GET/PUT | |
− | + | |- | |
+ | |'''Field name''' | ||
+ | |'''Type''' | ||
+ | |'''Description''' | ||
+ | |- | ||
+ | |c_name | ||
+ | |string | ||
+ | |Video Source Configuration Name | ||
+ | |- | ||
+ | |s_name | ||
+ | |String | ||
+ | |Name of the video source to be used by the configuration | ||
+ | |- | ||
+ | |in_use | ||
+ | |int | ||
+ | |Indicates whether or not the configuration is in use | ||
+ | |- | ||
+ | |action | ||
+ | |string | ||
+ | |Action on the configuration. Possible values: create, delete | ||
+ | |} | ||
− | + | Examples: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | <pre> | ||
+ | GET /configurations/sources/video | ||
+ | </pre> | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 165: | Line 204: | ||
} | } | ||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | <pre> | ||
+ | PUT /configurations/sources/video | ||
+ | </pre> | ||
+ | <syntaxhighlight lang="json"> | ||
− | + | { | |
− | + | "c_name": "configuration1", | |
− | + | "s_name":"video1", | |
− | + | "action": "create" | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ====/configurations/encoders/video==== |
− | + | Get information of all the video source configurations | |
− | + | Content type: JSON | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | {| class="wikitable" | ||
+ | !colspan="3"|GET/PUT | ||
+ | |- | ||
+ | |'''Field name''' | ||
+ | |'''Type''' | ||
+ | |'''Description''' | ||
+ | |- | ||
+ | |c_name | ||
+ | |string | ||
+ | |Video Encoder Configuration Name | ||
+ | |- | ||
+ | |e_name | ||
+ | |String | ||
+ | |Name of the video encoder to be used by the configuration | ||
+ | |- | ||
+ | |in_use | ||
+ | |int | ||
+ | |Indicates whether or not the configuration is in use | ||
+ | |- | ||
+ | |action | ||
+ | |string | ||
+ | |Action on the configuration. Possible values: create, delete | ||
+ | |} | ||
− | + | Examples: | |
+ | <pre> | ||
+ | GET /configurations/encoders/video | ||
+ | </pre> | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
− | |||
− | |||
− | {" | + | { |
− | + | "configurations": [ | |
− | + | { | |
− | ]} | + | "c_name": "configuration1", |
+ | "e_name":"H264", | ||
+ | "in_use": 1 | ||
+ | }, | ||
+ | { | ||
+ | "c_name": "configuration2", | ||
+ | "e_name":"H265", | ||
+ | "in_use": 0 | ||
+ | } | ||
+ | ] | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | <pre> | |
− | + | PUT /configurations/encoders/video | |
− | + | </pre> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{ | { | ||
− | + | "c_name": "configuration1", | |
− | + | "e_name":"H264", | |
− | + | "action": "create" | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ====/reboot ==== | ||
− | + | Reboots the system | |
− | + | Content type: JSON | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | {| class="wikitable" | ||
+ | !colspan="3"|GET | ||
+ | |- | ||
+ | |'''Field name''' | ||
+ | |'''Type''' | ||
+ | |'''Description''' | ||
+ | |- | ||
+ | |code | ||
+ | |int | ||
+ | |Http Error code | ||
+ | |- | ||
+ | |description | ||
+ | |String | ||
+ | |Human readable error description | ||
+ | |} | ||
Example: | Example: | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
− | { | + | {"status": { |
− | + | "code": 200, | |
− | + | "description": "Device has been reboot successfully" | |
− | + | } | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | ====/discovery ==== |
Enables or disables auto-discover functionality. | Enables or disables auto-discover functionality. | ||
+ | Content type: JSON | ||
− | + | {| class="wikitable" | |
− | + | !colspan="3"|GET/PUT | |
− | + | |- | |
− | + | |'''Field name''' | |
− | + | |'''Type''' | |
− | + | |'''Description''' | |
− | + | |- | |
+ | |enabled | ||
+ | |int | ||
+ | |0 Discovery disabled, 1 Discovery enabled | ||
+ | |} | ||
Example: | Example: | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
− | { | + | {"enabled": 1} |
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | ====/login ==== |
− | |||
+ | Logins using the ONVIF user, this returns a bearer token that needs to be used in every request to verify the user. | ||
+ | Content type: JSON | ||
− | + | {| class="wikitable" | |
− | + | !colspan="3"|PUT | |
− | + | |- | |
− | + | |'''Field name''' | |
− | + | |'''Type''' | |
− | + | |'''Description''' | |
− | + | |- | |
− | + | |username | |
− | + | |string | |
− | + | |User name | |
− | + | |- | |
− | + | |password | |
− | + | |string | |
+ | |User password | ||
+ | |} | ||
Example: | Example: | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
− | { | + | {"username": "username", |
− | + | "password": "password: | |
− | |||
− | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Return value: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | * '''sessionToken''': unique string assigned for every logged session. | |
− | + | ** ''type'': string | |
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 402: | Line 375: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ====/validateUser ==== | |
− | |||
− | === | ||
Validates if a token is still usable. | Validates if a token is still usable. | ||
+ | Content type: JSON | ||
− | + | {| class="wikitable" | |
− | + | !colspan="3"|PUT | |
− | + | |- | |
− | + | |'''Field name''' | |
− | + | |'''Type''' | |
− | + | |'''Description''' | |
− | + | |- | |
− | + | |sessionToken | |
− | + | |string | |
− | + | |unique string assigned for every logged session. | |
− | + | |} | |
− | + | Return value: | |
− | |||
− | |||
− | + | * '''valid''': int that specifies if the session token is valid. | |
− | + | ** ''type'': 1 for valid, 0 for invalid | |
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 432: | Line 402: | ||
<noinclude> | <noinclude> | ||
− | {{Onvif_Device_Reference_Design/Foot|Getting Started/Evaluating the Project|Getting Started/Purchasing a License}} | + | {{Onvif_Device_Reference_Design/Foot|Getting Started/Evaluating the Project using Docker|Getting Started/Purchasing a License}} |
</noinclude> | </noinclude> |
Latest revision as of 10:02, 5 March 2023
Make sure you also check Onvif Device Reference Design's companion project: Onvif device server |
ONVIF Device Reference Design | |
---|---|
Project Architecture | |
|
|
Getting Started | |
|
|
Reference Designs | |
|
|
Customizing the Project | |
|
|
Contact Us | |
|
Contents
Introduction
This project provides a REST API that can be used to access different capabilities of the device. This allows you to modify, for example, configurations, sources, and encoders by using REST requests.
Important considerations
- We are using Flask as an example of implementations for testing purposes, for commercial implementations, or an implementation exposed to the public, you need to use a server suited for deployment.
- The OpenSSL keys used are an example of an OpenSSL implementation, and they should be treated like that, for a final implementation we recommend generating or creating your own keys.
Supported requests
As previously mentioned, this project offers a REST API, these are the current supported requests.
Resources
/device-information
Gets the information of the device. Content type: JSON
GET | ||
---|---|---|
Field name | Type | Description |
firmware | string | Device Firmware Version |
serial_number | string | Device Serial Number |
hardware_id | string | Device Hardware ID |
model | string | Device Model |
manufacturer | string | Device Manufacturer |
Example:
GET /device-information
{"firmware": "1.0.0.0",
"serial_number": "123",
"hardware_id": "1",
"model": "model_1",
"manufacturer": "RidgeRun",
}
/sources/video
Get the information of all the video sources. Content type: JSON
GET/PUT | ||
---|---|---|
Field name | Type | Description |
name | string | Video Source name |
enabled | int | 1 enabled, 0 disabled |
Examples:
GET /sources/video
PUT /sources/video
{"sources":[
{"name":"video1","enabled":1},
{"name":"video2","enabled":1},
{"name":"video3","enabled":1}
]}
/encoders/video
Get the information of all the video encoders Content type: JSON
GET/PUT | ||
---|---|---|
Field name | Type | Description |
name | string | Video Encoder name |
enabled | int | 1 enabled, 0 disabled |
Examples:
GET /encoders/video
PUT /encoders/video
{"encoders":[
{"name":"h265","enabled":1},
{"name":"h264","enabled":0},
{"name":"mpeg","enabled":1}
]}
/configurations/sources/video
Get information of all the video source configurations Content type: JSON
GET/PUT | ||
---|---|---|
Field name | Type | Description |
c_name | string | Video Source Configuration Name |
s_name | String | Name of the video source to be used by the configuration |
in_use | int | Indicates whether or not the configuration is in use |
action | string | Action on the configuration. Possible values: create, delete |
Examples:
GET /configurations/sources/video
{
"configurations": [
{
"c_name": "configuration1",
"s_name":"video1",
"in_use": 1
},
{
"c_name": "configuration2",
"s_name":"video2",
"in_use": 0
},
{
"c_name": "configuration3",
"s_name":"video3",
"in_use": 1
},
]
}
PUT /configurations/sources/video
{
"c_name": "configuration1",
"s_name":"video1",
"action": "create"
}
/configurations/encoders/video
Get information of all the video source configurations Content type: JSON
GET/PUT | ||
---|---|---|
Field name | Type | Description |
c_name | string | Video Encoder Configuration Name |
e_name | String | Name of the video encoder to be used by the configuration |
in_use | int | Indicates whether or not the configuration is in use |
action | string | Action on the configuration. Possible values: create, delete |
Examples:
GET /configurations/encoders/video
{
"configurations": [
{
"c_name": "configuration1",
"e_name":"H264",
"in_use": 1
},
{
"c_name": "configuration2",
"e_name":"H265",
"in_use": 0
}
]
}
PUT /configurations/encoders/video
{
"c_name": "configuration1",
"e_name":"H264",
"action": "create"
}
/reboot
Reboots the system Content type: JSON
GET | ||
---|---|---|
Field name | Type | Description |
code | int | Http Error code |
description | String | Human readable error description |
Example:
{"status": {
"code": 200,
"description": "Device has been reboot successfully"
}
}
/discovery
Enables or disables auto-discover functionality. Content type: JSON
GET/PUT | ||
---|---|---|
Field name | Type | Description |
enabled | int | 0 Discovery disabled, 1 Discovery enabled |
Example:
{"enabled": 1}
/login
Logins using the ONVIF user, this returns a bearer token that needs to be used in every request to verify the user. Content type: JSON
PUT | ||
---|---|---|
Field name | Type | Description |
username | string | User name |
password | string | User password |
Example:
{"username": "username",
"password": "password:
}
Return value:
- sessionToken: unique string assigned for every logged session.
- type: string
{"sessionToken":session_token}
/validateUser
Validates if a token is still usable. Content type: JSON
PUT | ||
---|---|---|
Field name | Type | Description |
sessionToken | string | unique string assigned for every logged session. |
Return value:
- valid: int that specifies if the session token is valid.
- type: 1 for valid, 0 for invalid
{"valid": 1}