diff --git a/api/index.md b/api/index.md
index e3392d8bf..ae4633a54 100644
--- a/api/index.md
+++ b/api/index.md
@@ -1,7 +1,7 @@
---
layout: default
title: API
-nav_order: 0
+nav_order: 4
has_children: true
---
diff --git a/api/rest/v2/index.md b/api/rest/v2/index.md
index 35dc5b622..6064c4539 100644
--- a/api/rest/v2/index.md
+++ b/api/rest/v2/index.md
@@ -1,7 +1,7 @@
---
layout: default
title: REST (V2)
-nav_order: 10
+nav_order: 5
parent: API
has_children: true
published: true
@@ -200,9 +200,25 @@ To illustrate again using the Argentina example:
- All cities directly contained in Argentina (dcid: `country/ARG`): `country/ARG<-containedInPlace{typeOf:City}`
- All cities indirectly contained in Argentina (dcid: `country/ARG`): `country/ARG<-containedInPlace+{typeOf:City}`
-## Escape codes for reserved characters in GET requests
+{: #url-encode}
+## URL-encoding reserved characters in GET requests
-HTTP GET requests do not allow some of the characters used by Data Commons DCIDs and relation expressions. When sending GET requests, you may need use the [corresponding percent codes](https://en.wikipedia.org/wiki/Percent-encoding){: target="_blank"} for reserved characters.
+HTTP GET requests do not allow some of the characters used by Data Commons DCIDs and relation expressions. When sending GET requests, you may need to use the [corresponding percent codes](https://en.wikipedia.org/wiki/Percent-encoding){: target="_blank"} for reserved characters. For example, a query string such as the following:
+
+```
+https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId/06&property=<-*
+```
+ should be encoded as:
+
+```
+https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId%2F06&property=%3C-%2A
+```
+
+Although sometimes the original characters may work, it's safest to always encode them.
+
+> **Tip:** Don't URL-encode delimiters between parameters (`&`), separators between parameter names and values (`=`), or `-`.
+
+See [https://www.w3schools.com/tags/ref_urlencode.ASP](https://www.w3schools.com/tags/ref_urlencode.ASP){: target="_blank"} for a handy reference.
{: #pagination}
## Pagination
@@ -216,7 +232,7 @@ For example, the request:
```bash
curl --request GET \
- 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId/06&property=<-*'
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId%2F06&property=%3C-%2A'
```
will return something like:
@@ -228,7 +244,7 @@ will return something like:
"arcs": < ... output truncated for brevity ...>
},
},
- "nextToken": "SoME_veRy_L0ng_S+rIng"
+ "nextToken": "SoME_veRy_L0ng_STrIng"
}
```
@@ -236,7 +252,7 @@ To get the next set of entries, repeat the previous command and append the `next
```bash
curl --request GET \
- 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId/06&property=<-*&nextToken=SoME_veRy_L0ng_S+rIng'
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId%2F06&property=%3C-%2A&nextToken=SoME_veRy_L0ng_STrIng'
```
Similarly for POST requests, this would look like:
@@ -248,6 +264,7 @@ curl -X POST \
--data '{
"nodes": "geoId/06",
"property": "<-*",
- "nextToken": "SoME_veRy_L0ng_S+rIng"
+ "nextToken": "SoME_veRy_L0ng_STrIng"
}'
-```
\ No newline at end of file
+```
+Don't forget to URL-encode any special characters that appear in the string.
\ No newline at end of file
diff --git a/api/rest/v2/node.md b/api/rest/v2/node.md
index a336bc093..64f2bbbf0 100644
--- a/api/rest/v2/node.md
+++ b/api/rest/v2/node.md
@@ -1,7 +1,7 @@
---
layout: default
title: Get node properties
-nav_order: 3
+nav_order: 7
parent: REST (V2)
grand_parent: API
published: true
@@ -104,9 +104,9 @@ The response looks like:
## Examples
-### Example 1: Get all incoming arcs for a given node
+### Example 1: Get all incoming arc labels for a given node
-Get all incoming arcs of the node with DCID `geoId/06` by querying all properties with the `<-` symbol. This returns just the property labels.
+Get all incoming arc property labels of the node with DCID `geoId/06` by querying all properties with the `<-` symbol. This returns just the property labels but not the property values.
Parameters:
{: .example-box-title}
@@ -116,12 +116,21 @@ nodes: "geoId/06"
property: "<-"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
- 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId/06&property=<-'
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId%2F06&property=%3C-'
+```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/node \
+ -d '{"nodes": ["geoId/06"], "property": "<-"}'
```
Response:
@@ -142,7 +151,6 @@ Response:
}
}
```
-{: .example-box-content .scroll}
### Example 2: Get one property for a given node
@@ -156,12 +164,21 @@ nodes: "dc/03lw9rhpendw5"
property: "->name"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
- 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=dc/03lw9rhpendw5&property=->name'
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=dc%2F03lw9rhpendw5&property=-%3Ename'
+```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/node \
+ -d '{"nodes": ["dc/03lw9rhpendw5"], "property": "->name"}'
```
Response:
@@ -187,7 +204,6 @@ Response:
```
{: .example-box-content .scroll}
-
{: #multiple-properties}
### Example 3: Get multiple property values for multiple nodes
@@ -203,7 +219,16 @@ nodes: "geoId/06085", "geoId/06087"
property: "->[name, latitude, longitude]"
```
-Request:
+GET Request:
+{: .example-box-title}
+
+```bash
+curl --request GET --url \
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=geoId%2F06085&nodes=geoId%2F06087&property=-%3E%5Bname,%20latitude,%20longitude%5D'
+
+```
+
+POST Request:
{: .example-box-title}
```bash
@@ -310,12 +335,21 @@ nodes: "PowerPlant"
property: "<-*"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
- 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=PowerPlant&property=<-*'
+ 'https://api.datacommons.org/v2/node?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=PowerPlant&property=%3C-%2A'
+```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/node \
+ -d '{"nodes": ["PowerPlant"], "property": "<-*"}'
```
Response:
diff --git a/api/rest/v2/observation.md b/api/rest/v2/observation.md
index a4d6fe638..ef9f9d4cb 100644
--- a/api/rest/v2/observation.md
+++ b/api/rest/v2/observation.md
@@ -1,7 +1,7 @@
---
layout: default
title: Get statistical observations
-nav_order: 1
+nav_order: 6
parent: REST (V2)
grand_parent: API
published: true
@@ -38,20 +38,22 @@ X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI
JSON data:
{
"date": "DATE_EXPRESSION",
- "variable.dcids": [
+ "variable": {
+ "dcids": [
"VARIABLE_DCID_1",
"VARIABLE_DCID_2",
...
- ],
- "entity.dcids": [
+ ]
+ },
+ "entity": {
+ "dcids":[
"ENTITY_DCID_1",
"ENTITY_DCID_2",
...
- ],
- "entity.expression": ENTITY_EXPRESSION,
- "select": "variable",
- "select": "entity",
- ...
+ ]
+ "expression": "ENTITY_EXPRESSION"
+ },
+ "select": ["date", "entity", "variable", "value"]
}
@@ -174,9 +176,6 @@ With `select=date` and `select=value` specified, the response looks like:
Specify `date=LATEST` to get the latest observations and values. In this example, we select the entity by its DCID using `entity.dcids`.
-> Note: When sending a GET request, you need to use the following percent codes for reserved characters:
-- `%2F` for `/`
-
Parameters:
{: .example-box-title}
@@ -190,13 +189,22 @@ select: "value"
select: "date"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
'https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&date=LATEST&variable.dcids=Count_Person&entity.dcids=country%2FUSA&select=entity&select=variable&select=value&select=date'
```
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/observation \
+ -d '{"date": "LATEST", "variable": { "dcids": ["Count_Person"] }, "entity": { "dcids": ["country/USA"] }, "select": ["entity", "variable", "value", "date"] }'
+```
+
{: .example-box-content .scroll}
Response:
@@ -279,13 +287,23 @@ select: "value"
select: "variable"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
'https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&date=2015&variable.dcids=Count_Person&entity.dcids=country%2FUSA&entity.dcids=geoId%2F06&select=date&select=entity&select=value&select=variable'
```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/observation \
+ -d '{"date": "2015", "variable": { "dcids": ["Count_Person"] }, "entity": { "dcids": ["country/USA", "geoId/06"] }, "select": ["entity", "variable", "value", "date"] }'
+```
+
{: .example-box-content .scroll}
Response:
@@ -355,13 +373,6 @@ with date and value for each variable
([`Count_Person`](https://datacommons.org/tools/statvar#sv=Count_Person){: target="_blank"}) and
entity (all counties in California).
-> Note: When sending a GET request, you need to use the following escape codes for reserved characters:
-- `%3C` for `<`
-- `%2B` for `+`
-- `%7B` for `{`
-- `%3A` for `:`
-- `%7D` for `}`
-
Parameters:
{: .example-box-title}
@@ -375,13 +386,23 @@ select: "value"
select: "variable"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
'https://api.datacommons.org/v2/observation?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&date=2015&date=LATEST&variable.dcids=Count_Person&entity.expression=geoId%2F06%3C-containedInPlace%2B%7BtypeOf%3ACounty%7D&select=date&select=entity&select=value&select=variable'
```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/observation \
+ -d '{"date": "LATEST", "variable": { "dcids": ["Count_Person"] }, "entity": { "expression": "geoId/06<-containedInPlace+{typeOf:County}"}, "select": ["entity", "variable", "value", "date"] }'
+```
+
{: .example-box-content .scroll}
Response:
diff --git a/api/rest/v2/resolve.md b/api/rest/v2/resolve.md
index 4ea926124..7e956f438 100644
--- a/api/rest/v2/resolve.md
+++ b/api/rest/v2/resolve.md
@@ -1,7 +1,7 @@
---
layout: default
title: Resolve entities
-nav_order: 4
+nav_order: 8
parent: REST (V2)
grand_parent: API
published: true
@@ -135,14 +135,22 @@ Parameters:
nodes: "Q30"
property: "<-wikidataId->dcid"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
-'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Q30&property=<-wikidataId->dcid'
+'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Q30&property=%3C-wikidataId-%3Edcid'
+```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/resolve \
+ -d '{"nodes": ["Q30"], "property": "<-wikidataId->dcid"}'
```
-{: .example-box-content .scroll}
Response:
{: .example-box-title}
@@ -167,8 +175,6 @@ Response:
This queries for the DCID of "Mountain View" by its coordinates. This is most often represented by the [`latitude`](https://datacommons.org/browser/latitude){: target="_blank"} and [`longitude`](https://datacommons.org/browser/longitude){: target="_blank"} properties on a node. Since the API only supports querying a single property, use the synthetic `geoCoordinate` property. To specify the latitude and longitude, use the `#` sign to separate both values. This returns all the places in the graph that contains the coordinate.
-> Note: If using a GET request, use the percent code `%23` for `#`.
-
Parameters:
{: .example-box-title}
@@ -176,12 +182,22 @@ Parameters:
nodes: "37.42#-122.08"
property: "<-geoCoordinate->dcid"
```
-Request:
+
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
-'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=37.42%23-122.08&property=<-geoCoordinate->dcid'
+'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=37.42%23-122.08&property=%3C-geoCoordinate-%3Edcid'
+```
+
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/resolve \
+ -d '{"nodes": ["37.42#-122.08"], "property": "<-geoCoordinate->dcid"}'
```
{: .example-box-content .scroll}
@@ -191,7 +207,6 @@ Response:
```json
{
-
"entities" : [
{
"node" : "37.42#-122.08",
@@ -261,14 +276,21 @@ nodes: "Georgia"
property: "<-description->dcid"
```
-Request:
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
-'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Georgia&property=<-description->dcid'
+'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Georgia&property=%3C-description-%3Edcid'
+```
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/resolve \
+ -d '{"nodes": ["Georgia"], "property": "<-description->dcid"}'
```
-{: .example-box-content .scroll}
Response:
{: .example-box-title}
@@ -300,11 +322,6 @@ Response:
This queries for the DCID of "Georgia". Unlike in the previous example, here
we also specify its type using a filter and only get one place in the response.
-> Note: When sending a GET request, you need to use the following percent codes for reserved characters:
-- `%7B` for `{`
-- `%7D` for `}`
-
-
Parameters:
{: .example-box-title}
@@ -312,14 +329,22 @@ Parameters:
nodes: "Georgia"
property: "<-description{typeOf:State}->dcid"
```
-Request:
+
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
-'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Georgia&property=<-description%7BtypeOf:State%7D->dcid'
+'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Georgia&property=%3C-description%7BtypeOf:State%7D-%3Edcid'
+```
+POST Request:
+{: .example-box-title}
+
+```bash
+curl -X POST -H "X-API-Key: AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI" \
+ https://api.datacommons.org/v2/resolve \
+ -d '{"nodes": ["Georgia"], "property": "<-description{typeOf:State}->dcid"}'
```
-{: .example-box-content .scroll}
Response:
{: .example-box-title}
@@ -344,11 +369,6 @@ Response:
This queries for the DCIDs of "Mountain View" and "New York City".
-> Note: When sending a GET request, you need to use the following percent codes for reserved characters:
-- `%20` for space
-- `%7B` for `{`
-- `%7D` for `}`
-
Parameters:
{: .example-box-title}
@@ -356,16 +376,16 @@ Parameters:
nodes: "Mountain View, CA", "New York City"
property: "<-description{typeOf:City}->dcid"
```
-Request (GET):
+GET Request:
{: .example-box-title}
```bash
curl --request GET --url \
-'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Mountain%20View,%20CA&nodes=New%20York%20City&property=<-description%7BtypeOf:City%7D->dcid'
+'https://api.datacommons.org/v2/resolve?key=AIzaSyCTI4Xz-UW_G2Q2RfknhcfdAnTHq5X5XuI&nodes=Mountain%20View,%20CA&nodes=New%20York%20City&property=%3C-description%7BtypeOf:City%7D-%3Edcid'
```
{: .example-box-content .scroll}
-Request (POST):
+POST Request:
{: .example-box-title}
```bash
@@ -402,5 +422,5 @@ Response:
}
]
}
-
```
+{: .example-box-content .scroll}
diff --git a/api/rest/v2/sparql.md b/api/rest/v2/sparql.md
index ab55f053d..8a5a2c88c 100644
--- a/api/rest/v2/sparql.md
+++ b/api/rest/v2/sparql.md
@@ -1,7 +1,7 @@
---
layout: default
title: Query with SPARQL
-nav_order: 5
+nav_order: 9
parent: REST (V2)
grand_parent: API
published: true
diff --git a/api/rest/v2/troubleshooting.md b/api/rest/v2/troubleshooting.md
index e61bde59b..5fb8a809e 100644
--- a/api/rest/v2/troubleshooting.md
+++ b/api/rest/v2/troubleshooting.md
@@ -1,7 +1,7 @@
---
layout: default
title: Troubleshooting
-nav_order: 6
+nav_order: 10
parent: REST (V2)
grand_parent: API
published: true
@@ -29,7 +29,7 @@ published: true
}
```
-This is seen when your request is missing an API key. Please [request your own API key](/api/index.html#get-key).
+The request is missing an API key or the parameter specifying it is misspelled. Please [request your own API key](/api/index.html#get-key).
## Empty response
@@ -37,7 +37,7 @@ This is seen when your request is missing an API key. Please [request your own A
{}
```
-Sometimes your query might return an empty result. This is most commonly seen when the value provided for a query parameter is misspelled or doesn't exist. Make sure the values you are passing for parameters are spelled correctly.
+This is most commonly seen when the value provided for a query parameter is misspelled or doesn't exist. Make sure the values you are passing for parameters are spelled correctly, that you are correctly [URL-encoding](/api/rest/v2/index.html#url-encode) special characters in parameter values, and not URL-encoding parameter delimiters.
## Marshaling errors
@@ -55,4 +55,4 @@ Sometimes your query might return an empty result. This is most commonly seen wh
}
```
-This is most commonly seen when a query parameter is missing, misspelled or incorrect. Check the spelling of query parameters and ensure all required parameters are sent in the request.
\ No newline at end of file
+This is most commonly seen when a query parameter is missing, misspelled or incorrect. Check the spelling of query parameters, ensure all required parameters are sent in the request, that you are correctly [URL-encoding](/api/rest/v2/index.html#url-encode) special characters in parameter values, and not URL-encoding parameter delimiters.