API

    API Endpoint

        https://api.automap.ch/

Authentication

The authentication is based on an expiring token that you request using your AutoMap credentials. You recieve the token in json data. You can then use your token in subsequent request to launch AutoMap runs from the API.

POST /auth HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: api.automap.ch
{
    "username": "USERNAME"
    "password": "PASSWORD",
}

For example, using curl, an authentication request would look like:

curl  --url https://api.automap.ch/auth  \
--header 'content-type: application/json'   \
--data '{"username": "USERNAME", "password": "PASSWORD"}'

Here is a second example using python script:

import requests
url = 'https://api.automap.ch/auth'
data = {'username': 'USERNAME',
        'password': 'PASSWORD'}
response = requests.post(url = url, data = data)

if response.status_code != 200:
    print('An error occured')
    print(response.status_code)
    print(response.content)
    
else:
    print('Authentication token successfully retrieved')
    token = response.json()['token']

Launch request

To launch a new AutoMap run through the API, use the authentication token and a dictionary a parameters as described in the next section.

POST /launch HTTP/1.1
Accept: */*
Authorization: Token AUTHORIZATION_TOKEN
Host: api.automap.ch
{
    "key": "value",
    ...
}

For example, to launch an AutoMap run with python script, you could use the following code snippet:

import requests
import json
url = 'https://api.automap.ch/launch'

headers = dict()
headers['Authorization'] = 'Token {}'.format(token)
headers['Content-Type'] = 'application/json'
    
instructions = dict()
instructions['check'] = 0
instructions['aoi'] = 'aoi.geojson'
instructions['mode'] = 1
instructions['sats'] = 28
instructions['t0'] = '2018-01-01'
instructions['t1'] = '2018-06-01'
data = json.dumps(instructions)

response = requests.post(url, data=data, headers=headers)
if response.status_code != 200:
    print(response.status_code)
    print(response.content)
else:
    response_data = response.json()
    print(response_data)
Response

The response will include a URL on which the results of the run can be found. The results will be available as soon as possible. While an email is sent when using the online interfacte for launching AutoMap runs, the api does not offer a notifications systems.

{'valid': True,
'message': 'Launch submitted for processing',
'result-url': 'https://end-point/XXXXXXXXXXXXX.zip'}

Instruction parameters

Refer to the the Parameters Page for details explanations.

API only parameters
  1. check
  2. If set to 1, the request performs a syntax check and does not launch the AutoMap run. If set to 0, launch the AutoMap run.

Standard parameters
  1. mode
  2. choice between 0 (download), 1 (composite), or 2 (classify)

  3. sats
  4. integer of arbitrary order 2578 = 7528

  5. t0
  6. a date formated as YYYY-MM-DD

  7. t1
  8. a date formated as YYYY-MM-DD.

  9. stats
  10. Required for mode 'composite', list composed by name of methods available as arithmetic operation on numpy masked arrays.

  11. csv
  12. Name of a CSV sample file that was uploaded to your AutoMap account trough the interface or the API (see below).

  13. aoi
  14. Name of GEOJSON file that uploaded to your AutoMap account trough the interface or the API (see below).

  15. txt
  16. A short text to describe your run.

File upload

You can upload a file using the API.

POST /file HTTP/1.1
Accept: */*
Authorization: Token AUTHORIZATION_TOKEN
Content-Disposition: attachment; filename=FILENAME
Host: api.automap.ch

[file content]

Example using python script:

file_path = 'FILE PATH'
headers = dict()
headers['Authorization'] = 'Token {}'.format(token)
headers['Content-Disposition'] = 'attachment; filename=FILENAME'

with open(file_path, 'rb') as file:
    r = requests.post('https://api.automap.ch/file', files={'FILENAME': file}, headers=headers)

if response.status_code != 204:
    print(response.status_code)
    print(response.content)