How to properly format cURL JSON Request

 In this article, we will use the Data API quick-search request as an example.

curl -X POST "https://api.planet.com/data/v1/quick-search?" -H "Authorization: api-key ...." -H "Content-type: application/json" -H "Accept: application/json" -d '{
"item_types": [
"PSScene"
],
"filter": {
"type": "AndFilter",
"config": [
{
"type": "GeometryFilter",
"field_name": "geometry",
"config": {
"type": "Polygon",
"coordinates": [
[
[
141.7339735551446,
43.27522207886084
],
[
141.73326158304178,
43.2759699862455
],
[
141.73378537391056,
43.27623265962461
],
[
141.7345396473184,
43.27551028801348
],
[
141.7339735551446,
43.27522207886084
]
]
]
}
},
{
"type": "DateRangeFilter",
"field_name": "acquired",
"config": {
"gte": "2021-10-01T00:00:00Z",
"lte": "2022-12-29T15:13:46Z"
}
},
{
"type": "RangeFilter",
"field_name": "cloud_percent",
"config": {
"gte": 0,
"lt": 51
}
},
{
"type": "PermissionFilter",
"config": [
"assets:download"
]
}
]
}
}'

 

By searching on Planet Explorer with filters, you can click on the API {:} emblem on the bottom left hand side, then click on cURL <> to show the full request in a proper format.

Screenshot_2023-01-23_at_12.49.58_PM.png

If your formatting doesn't have the indentations as the above payload. Copy and paste the code into the body portion of Postman, and then click on Beautify (on the right hand side underneath "cookies"). This will beautify your code in one easy click for visualization purposes. 

Screenshot_2023-01-23_at_12.47.27_PM.png

Properly formatting your JSON request, and following the standard indentations for the request, can help you avoid many errors in your code.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.