Skip to content

Commit 5629eec

Browse files
authored
Merge pull request #49 from kristianrl/patch-1
Base URL and Python example added to api-key-access.rst - please fix the typography for the headings
2 parents fb95b19 + 8c23685 commit 5629eec

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Sphinx==4.3.2
1+
Sphinx==5.3.0
22
sphinx-rtd-theme==1.0.0
33
sphinx-autobuild==2021.3.14

source/internal-interface-design/api-key-access.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This can be done on the portal through the API key management pages. It can be a
1111

1212

1313
Usage
14-
^^^^^
14+
'''''
1515
With an API key, you can fetch and manage data in your OS2IoT system just as well as if you were a user on the browser.
1616
What you can access and manage is limited by the user group (-s) tied to the API key.
1717

@@ -20,15 +20,33 @@ With that in mind, let's dive into using an API key. Let's make a few assumption
2020
- We have an API key with the value :code:`00000000-abcd-ef00-0000-012345678901`
2121
- This API key is tied to a user group with Read priviliges to an organization and all its applications
2222
- There exists a :code:`GET` endpoint for fetching applications. The route ends with :code:`/application`
23+
- The Base URL for the OS2IOT Backend is known, e.g. :code:`https://os2iot-backend.SERVERNAME.EXAMPLE/api/v1/chirpstack/`
2324

2425
There's a broad variety of applications, terminals etc. which can perform HTTP requests. To authenticate this request
25-
with the API key, you must provide it as the header "x-api-key". Below, a screenshot is shown of how this is done in Postman.
26+
with the API key, you must provide it as the HTTP header "x-api-key".
27+
28+
Usage in Postman
29+
^^^^^^^^^^^^^^^^
30+
Below, a screenshot is shown of how this can be done in Postman.
2631

2732
|api-key-usage|
2833

2934
The bottom half of the screenshot is the response. The request was limited to 2 applications using the :code:`limit` query parameter.
3035
As seen, the backend responded with 2 (collapsed) applications.
3136

37+
Usage in Python
38+
^^^^^^^^^^^^^^^
39+
A simple example of making the API call in Python
40+
41+
.. code:: python
42+
43+
import requests
44+
url = "https://os2iot-backend.SERVERNAME.EXAMPLE/api/v1/application?limit=2&offset=0"
45+
headers = {
46+
'x-api-key': '00000000-abcd-ef00-0000-012345678901'
47+
}
48+
response = requests.request("GET", url, headers=headers)
49+
print(response.text)
3250
3351
Limitations
3452
^^^^^^^^^^^
@@ -43,4 +61,4 @@ For instance, to fetch the organization tied to your API key, you can make a :co
4361

4462
Currently, there's no expiration date on an API key. It will not expire unless an administrator revokes it on the key management page.
4563

46-
.. |api-key-usage| image:: ./media/api-key-usage.jpg
64+
.. |api-key-usage| image:: ./media/api-key-usage.jpg

0 commit comments

Comments
 (0)