- Legion API
- Fragments
- Create new fragment
Create new fragment
const url = 'https://legion.picogrid.com/v2/fragments';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"terminal_id":"example","stream_id":"example","timestamp":1,"location":{"type":"lat_lng_alt","altitude":1,"latitude":1,"longitude":1},"meta_data":{"additionalProperty":"example"},"payload":{"primitive_fragment_type":"blob","file_id":"example"}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://legion.picogrid.com/v2/fragments \ --header 'Content-Type: application/json' \ --data '{ "terminal_id": "example", "stream_id": "example", "timestamp": 1, "location": { "type": "lat_lng_alt", "altitude": 1, "latitude": 1, "longitude": 1 }, "meta_data": { "additionalProperty": "example" }, "payload": { "primitive_fragment_type": "blob", "file_id": "example" } }'Create a new fragment by specifying the properties of the new object in the request body
Request Bodyrequired
Section titled “Request Bodyrequired”Specify the fields of the fragment here
object
The time the fragment was recorded. The timestamp is an epoch milliseconds integer. See https://en.wikipedia.org/wiki/Unix_time for more information
Provide the latitude and longitude of the resource using WGS84, and the altitude of the resource in meters above sea level
object
The altitude of the resource in meters above sea level
Any additional metadata that that may be relevant for this type of fragment. See meta_data documentation for more information
object
object
This ‘blob’ type is for uploading arbitrary types of data to Legion that is stored in our blob storage and can be as large as needed. It must have the same primitive fragment type as the stream’s fragment type however.
To upload an arbitrarily sized fragment of any type to Legion we need you to first get an upload url from Legion, and then follow the instructions for that endpoint to upload the file. The response will contain a file_id which you need to specify here. You cannot create a blob fragment before the file has been uploaded to our blob storage.
object
This ‘json’ type is for uploading smaller json objects with a max size of 200kb. Remember that this primitive fragment type must also match the primitive fragment type of the stream’s fragment type you are uploading to
Any json object that represents your fragment is under 200kb in size
object
Responses
Section titled “Responses”Success
object
This key can be used as a discriminator for which type of fragment you have received. In this case the value is ‘blob’. The fragment is stored in our blob storage, which we use for large files and unstructured data, so we provide the fragment to you via the presigned url found in this object.
An http url you can send a GET request to in order to fetch the blob data of the fragment. If it is an image for example you can use this url directly in an <img> tag to display the image. The url is only valid for 24 hours, so will need to be refetched after that time if needed. The url should be treated as a secret token, and only shared with people you want to have access to the data.
The time the fragment was recorded. The timestamp is an epoch milliseconds integer. See https://en.wikipedia.org/wiki/Unix_time for more information
The time the fragment was received and created by Legion. The timestamp is an epoch milliseconds integer. See https://en.wikipedia.org/wiki/Unix_time for more information
Gives multiple different formats and units to choose between that all represent the location of the resource
object
Provides the latitude and longitude of the resource using WGS84, and the altitude of the resource in meters above sea level
object
The altitude of the resource in meters above sea level
Any additional metadata that that may be relevant for this type of fragment. See meta_data documentation for more information
object
object
This key can be used as a discriminator for which type of fragment you have received. In this case the value is ‘json’. The fragment is stored as a json object smaller than 200kb and is therefore provided directly in the json_data key in this object.
The json data which describes the fragment
object
The time the fragment was recorded. The timestamp is an epoch milliseconds integer. See https://en.wikipedia.org/wiki/Unix_time for more information
The time the fragment was received and created by Legion. The timestamp is an epoch milliseconds integer. See https://en.wikipedia.org/wiki/Unix_time for more information
Gives multiple different formats and units to choose between that all represent the location of the resource
object
Provides the latitude and longitude of the resource using WGS84, and the altitude of the resource in meters above sea level
object
The altitude of the resource in meters above sea level
Any additional metadata that that may be relevant for this type of fragment. See meta_data documentation for more information
object
Example
{ "primitive_fragment_type": "blob"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Bad Request Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Authentication Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Unauthorized Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Resource Not Found Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Timeout Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Bad Gateway Error
object
Examplegenerated
{ "message": "example"}Headers
Section titled “Headers”The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request’s credentials mode (Request.credentials) is include. - MDN Link
Version 2 · commit 0771262
