Help: COVE API User's Guide: Python Examples

 

Define Credentials

credentials.py:
'''Example: Define Credentials class for sending credentials header to COVE.'''
 
import base64
 
class Credentials:
'''Credentials: public class
All COVE API tools require authorization. Users must have an existing
username and password in COVE. Create an account at https://ceos-cove.org.
'''
header = None
 
def __init__(self, username, password):
'''Set header for all GET/POST requests using COVE API.'''
credentials = "{}:{}".format(username, password)
token = base64.b64encode(credentials.encode())
self.header = {
'Authorization': 'Basic ' + token.decode('utf-8')
}
 

Send API GET Request

get_request.py:
'''Example: Send GET request to COVE for User History'''
 
import requests
from credentials import Credentials
 
# Define API endpoint (request URL)
endpoint = 'https://ceos-cove.org/en/api/v1_2/acquisition_forecaster/'
 
# Set credentials
credentials = Credentials(username='<cove username>', password='<cove password>')
 
# Sent GET request
response = requests.get(url=endpoint, headers=credentials.header)
 
# Print results
print(response.json())
 

Send API POST Request

post_request.py:
'''Example: Submit a task to acquisition forecaster. '''
 
import requests
from credentials import Credentials
 
# Define API endpoint (request URL)
endpoint = 'https://ceos-cove.org/en/api/v1_2/acquisition_forecaster/'
 
# Define JSON data for request
data = {
"start_date": "2020-01-01",
"end_date": "2020-01-31",
"region_folder": "Africa",
"region": "Kenya",
"missions": [{
"mission": "Sentinel-1A",
"instrument": "C-SAR",
"mode": "IWS"
}]
}
 
# Define COVE credentials
credentials = Credentials(username='<cove username>', password='<cove password>')
 
# Send POST request
response = requests.post(url=endpoint, headers=credentials.header, json=data)
 
# Print results
print(response.json())