API Mechanics
Permissions
Most SpaceKnow API endpoints have a set of permissions required to access them.
A permission is a string with . as a namespace separator, for example
imagery.availability. All permissions act like a tree like structure where
longer permission is more specific than the shorter one.
The following Python code snipped shows how permissions are tested.
user_permission = user_permission_str.split('.')
required_permission = required_permission_str.split('.')
if len(user_permission) > len(required_permission):
return False
return all(user_permission[i] == required_permission[i] for i in range(len(required_permission)))
See the following example, where columns are permissions of a user and rows required permission.
|
|
|
|
|
|
true |
false |
false |
false |
|
true |
true |
false |
false |
|
true |
false |
false |
false |
|
false |
false |
false |
false |
|
false |
false |
false |
true |
Use Get User Info to list your permissions.
API Errors
The HTTP status code of 5XX is returned if a server-side error occurs. The
status code of 4XX is returned if a client-side error occurs.
Error Response body:
{
"error": "MACHINE-READABLE-ERROR-CODE",
"errorMessage": "A human readable error description."
}
Error codes and status codes each endpoint can return are listed in the
API reference. Requests failing with 429 or 503 can be
retried later.
Asynchronous APIs
Processes, that can take from minutes to hours, are handled asynchronously in
the “pipeline”. All APIs that work asynchronously have ../initiate and
../retrieve endpoints. To trigger a new pipeline, use ../initiate. To
check whether a pipeline is finished, request the Tasking API
get-status
endpoint. To get a finished pipeline result, request ../retrieve.
- POST /.../initiate
- Request JSON Object:
pipelineId (string) – ID of the processing pipeline. It will be used later to check pipeline status and to retrieve pipeline result.
status (string) – status of the pipeline at the time the response was generated. See get-status to learn more about pipeline statuses.
nextTry (int) – recommended delay in seconds before first status check.
subGeometryId (str) – This is only provided in Kraken Release initiate endpoint if
subGeometrywas present in the request. See Release with subGeometry.
Example response:
{ "nextTry": 5, "pipelineId": "3g4PovfhGxmymQolpgvv", "status": "NEW" }
Example with subGeometryId response:
{ "nextTry": 5, "pipelineId": "3g4PovfhGxmymQolpgvv", "status": "NEW", "subGeometryId": "0123456789abcdef" }
Pipeline is stopped and set to the FAILED status if an error occurred during
pipeline processing. Request on ../retrieve for the failed pipeline is
responded with a status code 424, and with a specific error code and message. See
API Errors.
- POST /.../retrieve
- Response JSON Object:
pipelineId (string) – required; ID of the pipeline whose result should be retrieved.
Example request:
{ "pipelineId": "3g4PovfhGxmymQolpgvv" }
Extent
Extent is a GeoJSON whose minimum bounding rectangle (MBR) is non-empty. All coordinates are considered to be expressed in WGS84 coordinate reference system.
Example extent:
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"coordinates": [
[
[
14.452436864376,
50.092111002982
],
[
14.451779723167,
50.092107561411
],
[
14.452233016491,
50.091543140472
],
[
14.452436864376,
50.092111002982
]
]
]
}
]
}
Extent Decomposition
Extent can be too large to be used with a particular API / system. We recommend to use Kraken API (Imagery and Analyses) in such cases.
This problem can be also solved on client side by decomposing the extent into a grid of smaller tiles (squares).
A simple decomposition determines the smallest bounding rectangle of the extent, whose side lengths are multiples of a desired tile size.
The bounding rectangle is then “cut” into square tiles. Tiles that do not intersect requested area could be omitted if desired.
Single tile has these properties:
square
intersection of the square with original polygon
The decomposition described above is “naive” as it uses a planar solution to the problem. It is recommended to use a CRS, which is a planar approximation of the earth in the area of the original extent.
API Response Headers
Following headers might be contained in API response:
SpaceKnow-Api-VersionSpaceKnow-Request-Id- unique identifier of the request. You may use it when contacting SpaceKnow engineering team about any technical issues.
Example response header:
HTTP/2 200
server: uvicorn
date: Wed, 03 Jan 2018 15:47:16 GMT
content-type: application/json; charset=utf-8
cache-control: no-cache
access-control-allow-origin: *
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Cloud-Trace-Context
strict-transport-security: max-age=2592000; includeSubDomains
via: 1.1 google
alt-svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
spaceknow-api-version: 106
spaceknow-request-id: 4bf92f3577b34da6a3ce929d0e0e4736
Paging
Some APIs may return a big number of results. To avoid large JSON responses, the
results are paginated using cursor as a pointer to a specific page.
Put parameter cursor to request an object to obtain a specific page.
Example of a specific page request:
{
"search": "*",
"cursor": "Pu9ZyvlVXxkm0XNr2FLr"
}
If the cursor is omitted, then the first page is returned.
Example of the first page request:
{
"search": "*"
}
Paginated APIs return cursor which is a pointer to the next page and
results which is a list of entities of the returned page.
Example of the paginated response:
{
"results": [
{
"name": "Enterprise 1"
},
{
"name": "Enterprise 2"
},
{
"name": "Enterprise 3"
},
{
"name": "Enterprise 4"
},
{
"name": "Enterprise 5"
}
],
"cursor": "Pu9ZyvlVXxkm0XNr2FLr"
}
cursor is null if the last page was returned.
Example of the last page response:
{
"results": [
{
"name": "Enterprise 6"
}
],
"cursor": null
}
Both normal and asynchronous APIs may be paginated. In the case of asynchronous APIs a new pipeline is started for every new requested page.