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['boundary_file'] = 'boundary_file.geojson'
instructions['mode'] = 'download'
instructions['satellites'] = [2, 'landsat']
instructions['start_date'] = '2018-01-01'
instructions['end_date'] = '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 Manual 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 "download", "composite" or "classify"

  3. satellites
  4. list satellite key, chosen within the following list: 2, 5, 7, 8, modis, landsat, all

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

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

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

  11. LAADS_key
  12. required if use of modis data or if mode 'classify' is chosen without submission of samples (csv).

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

  15. boundary_file
  16. Name of GEOJSON file that uploaded to your AutoMap account trough the interface or the API (see below).

  17. description
  18. 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)