Caltech Library logo

orcidtools

Orcid Tools

A command line tool called orcid, a set of Bash scripts and Go template for working with the Public ORCID API.

Configuration

The orcid tool and Bash scripts share a common configuration. These are set via environment variables. The following are supported, the first three required.

If you want to use the API URL https://pub.orcid.org then you’ll need to register an application to generate your client id and secret. This is free for most uses, if you follow the instructions

If you want to experiment with the orcid public api to test code (e.g. say test this package) you can use the Sandbox API which is full of fake data. ORCID has provided an example client id and secret described in their documentation along with the sandbox API URL of https://pub.sandbox.orcid.org.

The bash scripts provided in the repository rely on a few environment variables. You can define those variables in a Bash script, sourcing that script will then expose those variables in your current Bash session.

Below is an example of setup script that would be sourced to access the sandbox

    #!/bin/bash
    export ORCID_API_URL="https://pub.sandbox.orcid.org"
    export ORCID_CLIENT_ID="APP-01XX65MXBF79VJGF"
    export ORCID_CLIENT_SECRET="3a87028d-c84c-4d5f-8ad5-38a93181c9e1""

the ORCID tool

The command line tool works simularly to the bash scripts. You source a configuration then run the tool. Unlike the shell scripts login is automatic so you can focus on the command you need. The command line tool expacts an ORCID id as a command line parameter so it can get back a specific record.

    . etc/sandbox.sh
    orcid -works 0000-0003-0900-6903

Would list the works for the ORCID id of “0000-0003-0900-6903”. The resulting document would be in JSON form.

Taking things a step further you can generate a BibTeX from the works in your ORCID using the orcid tool and mkpage tool together with the templates included in this repository.

    . etc/sandbox.sh
    orcid -works-detailed 0000-0003-0900-6903 > 0000-0003-0900-6903-works.json
    mkpage "data=0000-0003-0900-6903-works.json" templates/works-detailed-to-bibtex.tmpl > 0000-0003-0900-6903.bib

We also include a simple example of tranferring an ORCID profile to a test file. This works on a record that has standard metadata present.

. etc/sandbox.sh
orcid -works-detailed 0000-0003-4476-2464 > 0000-0003-4476-2464-works.json
mkpage "data=0000-0003-4476-2464-works.json" templates/orcid2txt.tmpl > 0000-0003-0900-6903.txt

Working with the scripts

Assuming you saved this script as “etc/sandbox.sh” you would source it with the command

    . etc/sandbox.sh

You could then login to the API with

    ./scripts/api-login.sh

This will provide you with an Access token (you would cut and paste from the console to set that into the environment). Once ORCID_ACCESS_TOKEN is defined in your environment you then can use the other scripts to query the ORCID API for profile, bio and works data.

Putting it together

    . etc/sandbox.sh
    ./scripts/api-login.sh
    # Cut and past the 'export ORCID_ACCESS_TOKEN' line into the console
    # Then you can get the "works" for 0000-0003-0900-6903 with
    ./scripts/api-get-works.sh 0000-0003-0900-6903

Reference