Working with JSON responses Sentinel-HUB

Hello,

I’m trying to do a request do Sentinel-Hub API that returns JSON data instead of image data.
Can someone help me? I’ve already tried many things but it seems that nothing works.

Thanks.

Hi,

Can you please provide an example of your code so that we can help out? In addition, there are some examples in our documentation, for example, this one in the Sentinel-2 L2A examples. This user guide should also be useful to you.

If you need more guidance, will be happy to help :slight_smile:

I’ve already tried the examples available at SHUB docs but I always get “Format application/json does not support sample type AUTO” error.

The only time it worked, I received a json but I think that the data I received has no use for what I want.

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://services.sentinel-hub.com/api/v1/process');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
    'request' => '{
    "input": {
        "bounds": {
            "bbox": [
                13.822174072265625,
                45.85080395917834,
                14.55963134765625,
                46.29191774991382
            ]
        },
        "data": [
            {
                "type": "sentinel-2-l2a",
                "dataFilter": {
                    "timeRange": {
                        "from": "2018-12-27T00:00:00Z",
                        "to": "2018-12-27T23:59:59Z"
                    }
                }
            }
        ]
    },
    "output": {
        "responses": [
            {
                "identifier": "userdata",
                "format": {
                    "type": "application/json"
                }
            }
        ]
    }
}',
    'evalscript' => '//VERSION=3

function setup() {
  return {
    input: ["B02", "B03", "B04"],
    mosaicking: Mosaicking.ORBIT,
    output: { id:"default", bands: 3}
  }
}

function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
    outputMetadata.userData = { "scenes":  scenes.orbits }
}

function evaluatePixel(samples) {
  return [ 2.5 * samples[0].B04, 2.5 * samples[0].B03, 2.5 * samples[0].B02 ]
}'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$headers = array();
$headers[] = 'Authorization: Bearer <token>';
$headers[] = 'Accept: application/tar';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

print_r($result);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

?>

And I received a JSON with:

userdata.json0100644 0000000 0000000 00000001656 14406035503 012320 0ustar000000000 0000000 {"scenes":[{"tiles":[{"date":"2018-12-27T10:08:07Z","shId":563038,"cloudCoverage":54.68,"tileOriginalId":"S2B_OPER_MSI_L2A_TL_MPS__20181227T125927_A009443_T33TUL_N02.11","dataPath":"s3://sentinel-s2-l2a/tiles/33/T/UL/2018/12/27/0"},{"date":"2018-12-27T10:08:03Z","shId":562930,"cloudCoverage":33.68,"tileOriginalId":"S2B_OPER_MSI_L2A_TL_MPS__20181227T125927_A009443_T33TVL_N02.11","dataPath":"s3://sentinel-s2-l2a/tiles/33/T/VL/2018/12/27/0"},{"date":"2018-12-27T10:07:52Z","shId":562880,"cloudCoverage":7.81,"tileOriginalId":"S2B_OPER_MSI_L2A_TL_MPS__20181227T125927_A009443_T33TUM_N02.11","dataPath":"s3://sentinel-s2-l2a/tiles/33/T/UM/2018/12/27/0"},{"date":"2018-12-27T10:07:48Z","shId":562939,"cloudCoverage":0.07,"tileOriginalId":"S2B_OPER_MSI_L2A_TL_MPS__20181227T125927_A009443_T33TVM_N02.11","dataPath":"s3://sentinel-s2-l2a/tiles/33/T/VM/2018/12/27/0"}],"dateTo":"2018-12-27T23:59:59Z","__idx":0,"dateFrom":"2018-12-27T00:00:00Z"}]}

But I want to receive, for the BBox given, the percentage of the index used.

The SampleType error will refer to the SampleType of the data you are requesting. By default this UINT8.

Can you please elaborate more on what you require?

But I want to receive, for the BBox given, the percentage of the index used.

I don’t know what index you are referring to and do not understand what you mean by the “percentage of the index”

`

Basically, I’m trying to receive JSON data about watercourses and other features, using layers that I have configured on the Configuration Utility from Sentinel Hub.

Hi Rui,

This is still not clear at all what you are trying to achieve. Please provide code snippets and examples of your errors so that I can replicate and then help debug your code.

I actually don’t have any kind of request built because I have no idea how to do it.

Basically, so that you can understand, you can make image request to Sentinel-Hub API with certain parameters, such as cloud coverage, choose which satellite you want to use, etc. If you want you can also use EvalScripts/Custom Scripts that you’ve created or even use the one’s already created such as NDVI, NDWI, etc.

The thing is, at this point, I only was able to get image response (png, tiff, etc) but I couldn’t receive JSON response (basically an accurate description of what we can see at the image).

Something like:

Coords X1,Y1 : 0.4
Coords X2,Y2 : 0.1
(...)

Or something that can give me the index values for each coords (for the given BBox).

If you are only interested in the statistics then you probably want to look using Statistical API. In your Statistical API request, you can specify your area of interest, time period, evalscript and which statistical measures should be calculated. You can find examples of the API here.

To familiarise yourself with the Statistical API, I recommend checking the Requests builder, our API reference and our Statistical API webinar.

If I’m not mistaken, the Statistical API returns data with a range of values, right?
My main goal is to obtain those band values BUT the exact values and coordinates (basically an “image description”), with this return, for example:

{
   [bbox coords],
   ["b1": 0.2, ...]
},

{
   [other bbox coords],
   ["b1": 0.8, ...]
}

Hi Rui,

Out-of-the-box, our services do not provide what you are trying to do. However, you could try some workaround solution as a post-processing step. A while back, some users were trying to do something similar:

This might help you develop a piece of code that formats the data in the desired format.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.