Page tree

Versions Compared

Key

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

Getting your API Key

Your API authentication key is available from your account's setting. It is a private key and should not be shared.  You can access your account settings from the top menu by clicking on your username. 

The link will open your account's settings page. Your API key is the last element in the side bar. 

Accessing gDMCP using Python

 

Code Block
languagepy
titlegDMCP API - Add new dataset from g2
linenumberstrue
#!/usr/bin/env python 
import json
import requests
import sys
import os
from shutil import copyfile
import pprint


# This sample gets the file name and path (from g2) then copy the file to the gDMCP project
# Then upload it to the system
filename, file_extension=os.path.splitext(os.path.basename(sys.argv[1]))
copyfile(sys.argv[1],'/projects/p094_swin/public_data/data_share/'+filename+file_extension)
# Put the details of the dataset we're going to create into a dict.  
#/projects/p094_swin/public_data/data_share     
dataset_dict = {
    'package_id': sys.argv[2],
    'gstar_path': sys.argv[1],
    'url': '',
    'name': filename,
    'notes': filename,
}

## You need your User API Authorization Key
headers = {
    'Authorization': 'xxxxxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxxxx'
}

# Use the json module to dump the dictionary to a string for posting.   
# We'll use the package_create function to create a new dataset. 
url =    'https://data-portal.hpc.swin.edu.au/api/action/resource_create'
response = requests.post(url, json=dataset_dict, headers=headers)

# Use the json module to load CKAN's response into a dictionary.   
response_dict = response.json()
assert response_dict['success'] is True

# package_create returns the created package as its result.      
created_package = response_dict['result']
print created_package['url']

More details about the API access to gDMCP can be found on http://docs.ckan.org/en/ckan-1.7.4/api-tutorial.html