Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The carried body contains the authentification credentials as a dict element. The auth cookie is then extracted (theToken) from the response of the POST request (see http requests).

Code Block
languagepy
themeEmacs
import requests
import json

auth = requests.post('https://sandbox.sensor.awi.de/rest/sensors/contacts/login'
	                 , data = {'username': <yourUserName>, 'authPassword': <yourSecretPassword>}
)
theToken = auth.cookies['x-auth-token']

...

HTTP requests

GET

This gets basic information about an item. The result is a dictionary object.

Code Block
languagepy
themeEmacs
a = requests.get('https://sandbox.sensor.awi.de/rest/sensors/item/getItem/456')
theItem = json.loads(a.content)

...

PUT

You need proper privileges to modify items.

This puts a new item to sensor.awi.de.

...

Code Block
languagepy
themeEmacs
requests.put('https://sandbox.sensor.awi.de/rest/sensors/item/createItem'
             , data = json.dumps({
                 "description": "string"
                 , "shortName": "anotherteststring"
                 , "longName": "string"
                 , "serialNumber": "string"
                 , "manufacturer": "string"
                 , "parentID": 0
                 , "applicationTypeID": 0
                 , "model": "string"
                 , "inventoryNumber": "string"
                 , "itemStatusID": 2
                 , "itemTypeID": 110
                 , "id": 0
             })
             , headers = {"content-type": "application/json"}
             , cookies = {'x-auth-token': theToken}
    )

...

  • "description": string --> for the overview tab
  • "shortName": string --> for the overview tab
  • "longName": string --> for the overview tab
  • "serialNumber": string --> for the overview tab
  • "manufacturer": string --> for the overview tab
  • "parentID": integer --> left blank if item should be parentless, otherwise enter numeric id of parental item (think about access rights for the parent, too)
  • "applicationTypeID": ignore
  • "model": string --> for the overview tab
  • "inventoryNumber": string --> for the overview tab
  • "itemStatusID": integer --> either know the necessary id or ask https://sandbox.sensor.awi.de/rest/sensors/item/getAllItemStatuses, in this case 2 refers to construction
  • "itemTypeID": integer --> either know the necessary id or ask https://sandbox.sensor.awi.de/rest/sensors/item/getAllItemCategories, in this case 110 is a sediment_grab
  • "id": integer --> set 0, since the item is supposed to be completly new

...

This deletes a certain user with a specific role from a certain item.

Code Block
languagepy
themeEmacs
requests.delete('https://sandbox.sensor.awi.de/rest/sensors/contacts/deleteContactFromDevice/10877/80/29'
                , cookies = {'x-auth-token': theToken}
                , headers = {'content-type': 'application/json'}
  )

...

  • 10877: the item ID
  • 80: the user ID
  • 29: the contact role ID

...

The carried body contains the authentification credentials as a list element. The auth cookie is then extracted (theToken) from the response of the POST request (see http requests).

Code Block
languagebash
themeFadeToGrey
library('httr')

x <- POST(url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/login'
        , body = list("username" = '<yourUserName>', "authPassword" = 'yourSecretPassword')
        , encode = "form"
          )
theToken <- x$cookies$value[2]

...

HTTP requests

GET

This gets basic information about an item. The result is a list object.

Code Block
languagebash
themeFadeToGrey
GET(url = 'https://sandbox.sensor.awi.de/rest/sensors/item/getItem/456')

PUT

You need proper privileges to modify items.

...

  • url: the API endpoint to call
  • add_headers: contains the wrapped auth cookie
  • body: a list (that is then translated to json) that holds the info about the item to be created
  • encode: indicates how the submitted values are encoded, in this case we preferred json
Code Block
languagebash
themeFadeToGrey
PUT(url = 'https://sandbox.sensor.awi.de/rest/sensors/item/createItem'
  , add_headers("x-auth-token" = theToken)
  , body = list(description= "string"
              , shortName = "testnashalalastring"
              , longName = "string"
              , serialNumber = "string"
              , manufacturer = "string"
              , parentID = 0
              , applicationTypeID = 0
              , model = "string"
              , inventoryNumber = "string"
              , itemStatusID = 2
              , itemTypeID = 110
              , id= 0
                )
  , encode = 'json'
    )

...

  • "description": string --> for the overview tab
  • "shortName": string --> for the overview tab
  • "longName": string --> for the overview tab
  • "serialNumber": string --> for the overview tab
  • "manufacturer": string --> for the overview tab
  • "parentID": integer --> left blank if item should be parentless, otherwise enter numeric id of parental item (think about access rights for the parent, too)
  • "applicationTypeID": ignore
  • "model": string --> for the overview tab
  • "inventoryNumber": string --> for the overview tab
  • "itemStatusID": integer --> either know the necessary id or ask https://sandbox.sensor.awi.de/rest/sensors/item/getAllItemStatuses, in this case 2 refers to construction
  • "itemTypeID": integer --> either know the necessary id or ask https://sandbox.sensor.awi.de/rest/sensors/item/getAllItemCategories, in this case 110 is a sediment_grab
  • "id": integer --> set 0, since the item is supposed to be completly new

...

This deletes a certain user with a specific role from a certain item.

Code Block
languagebash
themeFadeToGrey
DELETE(url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/deleteContactFromDevice/10877/80/29'
  , add_headers("x-auth-token" = theToken)
  )

...

  • 10877: the item ID
  • 80: the user ID
  • 29: the contact role ID

...