Versions Compared

Key

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

...

Info

After generating the API key, copy the key and store it in a secure place (Note: The API key is only displayed once in the API Key Information page [see figure 2 above] - and will not be shown or accessible after this - for security reasons). if you lose the API Key you need to generate a new key.

How to use the API Key

...

4. To retrieve the packages, select the /packages GET method (4), then click on Try in it out(4a), then click on Execute (4b)

...

  1. In your computer, open the terminal then type in: curl -H 'X-Api-Key: <apikey>' https://ecoimages.tern.org.au/api/whoami (e.g. curl -H 'X-Api-Key: fakebmRSFNPXSF5aiI7OjpUM1s6eiANQmgyKF8NJjRpZFJqSGMlPWlRVQlGKndoUzI4JXhkVSY/b2IL' https://ecoimages.tern.org.au/api/whoami

  2. The output should be similar to what is shown in figure Figure 7:

...

Figure 7

This step shows that you are able to reach the endpoint /api/whoami in the TERN EcoImages portal and that your API key is valid (because this endpoint requires a valid API key to allow you to retrieve your details). Subsequently, this means you can also use other publicly available endpoints from the TERN portals using the supplied API key.

1.2 Curl with Basic authentication type

  1. In the terminal type in: curl --user <apikey>:<password> <tern application endpoint>. Make sure that the <password> is blank! (e.g. curl --user FAKEAPIKEY123: https://ecoimages.tern.org.au/api/v1.0/packages)

  2. Figures 8 and 9 below demonstrate how you can retrieve a list of the packages you have downloaded from the TERN EcoImages Portal using curl with a basic authentication type method. Figure 8 is the curl command. Figure 9 is the JSON result of the packages.

...

(Hint: If you have installed the jq command-line tool, you can pipe the output to format the response JSON string nicely [pretty print], as figure Figure 8 below shows!)

...

Figure 9

3. Using Wget command-line tool

...

--mirror: instruct wget to follow links and download every link encountered on the same site
--np: don’t follow links into parent directories
--e robotos=off: wget mirroring follows instructions in the robots.txt file. this option tells wget to ignore it

...

4. Using ffmpeg

ffmpeg is the swiss Swiss army knife to work with audio and video data. It also works well with our acoustic data.

The following example extracts 30 seconds of audio data (starting from a specific offset), re-samples the audio to 22kHz, and stores the result as a WAV file. Total The total download for this example is about 17MB out of a ~800MB file.

...

The same results can be achieved as in the above examples using a python Python script (or a full-blown pythonPython, Django, or React application). The following is an example of a small python Python script to retrieve your details using the endpoint /api/whoami in the EcoImages portal:

Code Block
breakoutModewide
languagepy
import requests

API_KEY = "fakeRnZRTC5Nfk8/bjk1SSFNPXp5KSFF8NJjRpZFJqSGMlPWlRVQlGKndoUzI4JXhkVSY/b2IL"
URI = "https://ecoimages.tern.org.au/api/whoami"

headers = {
    "X-Api-Key": API_KEY
}
result = requests.get(URI, headers=headers)
print(result.json())

####Results#####
{'email': 'user@adelaide.edu.au', 'email_verified': True, 'family_name': 'FamilyName', 'given_name': 'User', 'id': '97e6e762-257f-4e31-8cb4-9a30d578194b', 'name': 'UserName', 'roles': ['admin'], 'scopes': ['email', 'profile']}

Another example Python script example to retrieve a list of packages in the EcoImages portal

Code Block
breakoutModewide
languagepy
import requests

API_KEY = "fakeTUd5QnpwRnZRTC5Nfk8/bjk1SSFNJjRpZFJqSGMlPWlRVQlGKndoUzI4JXhkVSY/b2IL"
URI = "https://ecoimages.tern.org.au/api/v1.0/packages?page_size=1&page_num=1"

headers = {
    "X-Api-Key": API_KEY
}
result = requests.get(URI, headers=headers)
print(result.json())

###Results######
{"current_count": 1, 
    "packages": [
        {"can_download": True, 
            "can_mint_package": True, 
            "can_request_download": False, 
            "can_update_package": True, 
            "description": "Dete again", 
            "doi": "", 
            "doi_requested": False, 
            "download_file_format": "zip", 
            "eta": -1, 
            "expiration_date": "2022-01-26", 
            "is_my_package": True, 
            "online_status": "In Progress", 
            "package_id": "41e3ef57532011ecb2aae22c8c1c3fad", 
            "package_location": "/api/v1.0/packages/41e3ef57532011ecb2aae22c8c1c3fad", 
            "package_status": "Complete", 
            "progress": 100, 
            "query": {"from": 0, "image_type": ["ancillary.general"], "page_num": 1, "page_size": 8000}, 
            "request_date": "2021-12-02", 
            "title": "Test again delete initialized", 
            "zip_progress": 100, 
            "zip_status": "Complete"
            }
            ], 
            "total_packages": 18
        }

...

For more EcoImages Portal public API endpoints (which have been used in the above demonstrations), please refer to the EcoImages production API dashboard https://ecoimages.tern.org.au/api/v1.0/ui#/. From With the endpoints listed in the API Swagger Dashboard, you can build your own extensive applications.

...

(Hint: The EcoImages portal: https://ecoimages.tern.org.au was built using API endpoints in https://ecoimages.tern.org.au/api/v1.0/ui#/ . Hence, having the API Key can be a powerful tool , enabling you to build your own applications similar to the EcoImages portal [or just a small, targeted python scripts for your own requirements]! . - see other Swagger APIs here)

...