REST API description: Difference between revisions

describe API token usage
No edit summary
(describe API token usage)
Line 16: Line 16:


The credentials are the same as for the web interface. Users with the admin role are allowed to access all APIs per default. With version 4.1 the access can be configured/restricted in the role settings. A non-admin user has read access to most of the statistics. If you have enabled the pcap role, the capture URL is also possible for the API.
The credentials are the same as for the web interface. Users with the admin role are allowed to access all APIs per default. With version 4.1 the access can be configured/restricted in the role settings. A non-admin user has read access to most of the statistics. If you have enabled the pcap role, the capture URL is also possible for the API.
Starting with verison 4.2., it is possible to use [[User Profile Settings|API tokens]] instead of username/password. Permissions for API tokens can be configured when creating the token.


Allegro Packets recommends to set up a separate non-admin user with or without the pcap role for the REST API of only statistics shall be gathered. This will prevent to accidentally shut down or change any configuration by calling the REST API.
Allegro Packets recommends to set up a separate non-admin user with or without the pcap role for the REST API of only statistics shall be gathered. This will prevent to accidentally shut down or change any configuration by calling the REST API.
Line 27: Line 29:
The parameter '''-u''' allows you to set a user name and password for the request.  
The parameter '''-u''' allows you to set a user name and password for the request.  


The parameter '''-k''' will allow self-signed certificates.
The parameter '''-k''' will allow self-signed certificates. This is not necessary if a proper trusted certificate is installed on the Allegro Network Multimeter.


The parameter '''-s''' or '''--silent''' mutes any debugging output.
The parameter '''-s''' or '''--silent''' mutes any debugging output.
Line 36: Line 38:


Please note that you might need to use <code>curl.exe</code> in windows.
Please note that you might need to use <code>curl.exe</code> in windows.
==== Using API token ====
When using an API token, the authentication is added using parameter '''-H''' to add a special HTTP request header (with '''API_TOKEN''' as a placeholder for the real token):
curl --silent -k -H "Authorization: Bearer API_TOKEN" '<nowiki>https://allegro-mm-XXX/...'</nowiki>


=== PowerShell ===
=== PowerShell ===
Line 59: Line 65:


<pre>Invoke-RestMethod -Uri 'https://allegro-mm-XXXX/...' -Headers @{Authorization = ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 'USER', 'PASSWORD'))))} -ContentType'application/json; charset=utf-8' -Method 'Get' -SkipCertificateCheck</pre>
<pre>Invoke-RestMethod -Uri 'https://allegro-mm-XXXX/...' -Headers @{Authorization = ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 'USER', 'PASSWORD'))))} -ContentType'application/json; charset=utf-8' -Method 'Get' -SkipCertificateCheck</pre>
==== Using API token ====
When using an API token, the Authorization header changes (with API_TOKEN as a placeholder for the real token):
Invoke-RestMethod -Uri '<nowiki>https://allegro-mm-XXXX/...'</nowiki> -Headers @{Authorization = ("Bearer API_TOKEN")} -ContentType'application/json; charset=utf-8' -Method 'Get' -SkipCertificateCheck


=== jq ===
=== jq ===
28

edits