Skip to content

whomingbird/SEEK-API-Workshop

Repository files navigation

SEEK API Workshop

Links

General hints

Easily access information via your browser

Get download link

Basic operations (python)

  • headers
    • please see 01_Person.ipynb for further details
      headers = {"Content-type": "application/vnd.api+json",
                 "Accept": "application/vnd.api+json",
                 "Accept-Charset": "ISO-8859-1"}
  • read
    • use a function
      def json_for_resource(type, id):    
          # REM directly using 'requests' will only work for public resources,
          # for protected resources use your 'session' here
          r = requests.get(base_url + "/" + type + "/" + str(id), headers=headers)
          if (r.status_code != 200):
              print(r.json())
          r.raise_for_status()
          return r.json()
    • usage: json_for_resource('[insert_type_here]',my_type_id)
  • insert
    • session.post(base_url + '/[insert_type_here]', json=my_type)
  • update
    • session.put(blob_url, data=my_data, headers={'Content-Type': 'application/octet-stream'})
  • delete
    • session.delete(base_url + my_type['data']['links']['self'])
  • what types are defined?
    • see the documentation
    • assays, data_files, events, institutions, investigations, models, people, presentations, programmes, projects, publications, sample_types, sops, studies
  • authentication
    • basic authentication for using write access and requesting protected resources, you need to create a session
      session = requests.Session()
      session.headers.update(headers)
      session.auth = (input('Username:'), getpass.getpass('Password'))
    • API token
      1. in order to authenticate you when performing API requests, you need to create an API token. You can create your token with the following steps: "My profile" => "Action" => "API tokens"=> "New API token"
      2. include the token in header
        headers = {
               "Content-type": "application/vnd.api+json",
               "Accept": "application/vnd.api+json",
               "Accept-Charset": "ISO-8859-1",
               "Authorization: Token {my_token}" 
               }

Information and further reading

All Jupyter-Notebooks in this repository are originally from this project.

Find more Jupyter-Notebooks, examples and Exercises here:

Usage examples

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published