Green Commons uses a custom HTTP Authentication scheme in order to authenticate the requests. For resources requiring authentication, you need to pass the Authorization
header in the following format:
Authorization: GC access_key:secret_key
Your access_key
and secret_key
can be found in your profile. In the curl
request examples below, fake keys are being used (access_key
and secret_key
), replace them with your personal keys. You will also want to change the IDs in order to interact with real resources.
The Green Commons Web API follows the JSON API specification to facilitate the integration in your projects. Specify the content-type of your request using by setting the Content-Type
header.
Content-Type: application/vnd.api+json
The search endpoint can be used to search through resources, networks and lists. It accepts some query parameters allowing you to customize the results.
Query Parameters
q
: The term to search for.filters
: Filters to apply to the search. For now, results can only be filtered by class orresource_type
. Supported Values:filters[resource_types]=articles,books,reports,urls,audios,courses,datasets,images,syllabuses,videos,profiles
filters[model_types]=resources,lists,networks
sort
: Field to sort the results by. Supported Values:sort=published_at
(Ascending)sort=-published_at
(Descending)
page
: The page to retrieve.per
: Number of results per page.
More filters and sorting options are coming soon.
Example
curl -g -X GET 'https://greencommons.net/api/v1/search?q=wind&filters[resource_types]=articles,reports&filters[model_types]=resources,lists,networks&page=2&per=5'
{
"data":[
{
"type":"resources",
"id":"504",
"attributes":{
"title":"The Upside of Down: Catastrophe, Creativity, and the Renewal of Civilization",
"excerpt":"...",
"published_at":"2017-01-05T14:14:49.305Z",
"tags":[],
"resource_type":"article"
},
"links":{
"self":"https://greencommons.net/api/v1/resources/504"
},
"relationships":{
"lists":{
"data":[
],
"links":{
"self":"https://greencommons.net/api/v1/resources/504/relationships/lists",
"related":"https://greencommons.net/api/v1/resources/504/lists"
}
}
}
},
{ ... }
],
"links":{
"self":"https://greencommons.net/api/v1/search?q=wind&filters[resource_types]=articles,reports&filters[model_types]=resources,lists,networks&page=2&per=5",
"next":"",
"last":""
},
"included":[]
}
curl https://greencommons.net/api/v1/resources/43130
Or to access a private resource belonging to you:
curl -H 'Authorization: GC access_key:secret_key' \
https://greencommons.net/api/v1/resources/63243
curl https://greencommons.net/api/v1/resources \
-X POST \
-v \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "type": "resources", "attributes": { "title": "A new resource" } } }'
curl https://greencommons.net/api/v1/resources/63244 \
-X PATCH \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "id": "63244", "type": "resources", "attributes": { "title": "An updated resource" } } }'
All the query parameters defined for the /search
resource can be used here as well.
curl https://greencommons.net/api/v1/networks
Example
curl https://greencommons.net/api/v1/networks/2129
curl https://greencommons.net/api/v1/networks \
-X POST \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "type": "networks", "attributes": { "name": "A new network" } } }'
curl https://greencommons.net/api/v1/networks/2140 \
-X PATCH \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "id": "2140", "type": "networks", "attributes": { "name": "A new network" } } }'
curl https://greencommons.net/api/v1/networks/2140/relationships/users
Note that it is also possible to just include the members when retrieving a network:
curl 'https://greencommons.net/api/v1/networks/2140?include=users'
curl https://greencommons.net/api/v1/networks/2140/relationships/users \
-X POST \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": [{ "id": "1", "type": "users" }] }'
curl https://greencommons.net/api/v1/networks/2140/relationships/users \
-X DELETE \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": [{ "id": "1", "type": "users" }] }'
Example
curl https://greencommons.net/api/v1/lists/93
curl https://greencommons.net/api/v1/lists \
-X POST \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "type": "lists", "attributes": { "name": "A new list" } } }'
curl https://greencommons.net/api/v1/lists/93/relationships/items \
-X POST \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": [{ "id": "2140", "type": "networks" }, { "id": "43130", "type": "resources" }] }'
curl https://greencommons.net/api/v1/lists/93/relationships/items \
-X DELETE \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": [{ "id": "2140", "type": "networks" }, { "id": "43130", "type": "resources" }] }'
curl https://greencommons.net/api/v1/users \
-X POST \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "type": "users", "attributes": { "email": "[email protected]", "password": "password", "password_confirmation": "password"} } }'
curl https://greencommons.net/api/v1/users/10 \
-X PATCH \
-H 'Authorization: GC access_key:secret_key' \
-H 'Content-Type: application/vnd.api+json' \
-d '{ "data": { "id": "10", "type": "users", "attributes": { "first_name": "John" } } }'