MCC - API POST

Template for making API calls to Metadata Compliance Checker (MCC) using a local netCDF or HDF file, and outputing the response to JSON

MCC Endpoints

PROD - https://mcc.podaac.earthdatacloud.nasa.gov/

UAT - https://mcc.podaac.uat.earthdatacloud.nasa.gov/mcc

import json
import requests
import sys

# Choose VENUE: UAT or PROD
mcc_env = 'UAT'
mcc_env = 'PROD'

MCC Dictionary - Environments

url_dict = {
    'UAT': "https://mcc.podaac.uat.earthdatacloud.nasa.gov/mcc",
    'PROD': "https://mcc.podaac.earthdatacloud.nasa.gov/"
}

mcc_host = url_dict.get(mcc_env)
# Print
print(mcc_env, " - " , mcc_host)

MCC - API POST query example (for a local file)

See https://mcc.podaac.earthdatacloud.nasa.gov/mcc/about_api for a description of the query parameters (accessed via payload{} dictionary in this example)

url = mcc_host + "/check"

payload = {
'ACDD':'on',
'ACDD-version':'1.3',
'CF':'on',
'CF-version':'1.7',
'response':'json',
}


# set the path and filename to upload to MCC
dirname = "my_local_path_to_the_file"
filename = "myFile.nc"

# working examples . . . comment out, modify or remove these two lines as needed
dirname = "./data/"
filename = "ascat_20210101_000900_metopa_73696_eps_o_coa_3202_ovw.l2.nc"


files=[
  ('file-upload',
   (
    filename,   
    open(dirname+filename,'rb'),'application/octet-stream'

   )
  )
]

headers = {}

# Ping the API; format the response in json; pretty print the json response
response = requests.request("POST", url, headers=headers, data=payload, files=files)
json_resp = json.loads(response.text)
json_resp_formatted = json.dumps(json_resp, indent=2)
print(json_resp_formatted)