Curl Post method Sentinel on Flutter

I need to extract the dates through the Sentinel server. On the Sentinel page there is an example using Curl but I’m having problems: Http Status 500 Internal Server Error and I don’t know how to solve it and i tried to find some solution without success. I already have the token and the problem is not authentication. Here is the sample code for sentinel:

Sentinel link: Where can I get a list of the available imagery dates for a specific area?

curl -X POST 'services.sentinel-hub.com/api/v1/catalog/search' \
-header 'Authorization: Bearer <your access token>' \
-header 'Content-Type: application/json' \
-data-raw '{
    "bbox": [13,45,14,46],
    "datetime": "2019-12-10T00:00:00Z/2020-12-15T00:00:00Z",
    "collections": ["sentinel-1-grd"],
    "limit": 50,
    "distinct": "date"
}'

And here is the Dart code:

 var url = 'http://services.sentinel-hub.com/api/v1/catalog/search';
    Map<String, dynamic> body = {
      "bbox": "[13, 45, 14, 46]",
      "datetime": "2019-12-10T00:00:00Z/2020-12-15T00:00:00Z",
      "collections": ["sentinel-2-l2a"],
      "limit": 50,
      "distinct": "date"
    };

    var response = await http.post(
      url,
      headers: {
        'Authorization': 'Bearer <your access token>',
        'Content-Type': 'application/json',
      },
      body: json.encode(body),
    );

Thanks in advance :slight_smile:

Hello!

I just had a look at your problem. Do you get an additional error message besides 500 Internal Server Error?

Best regards
Pontus

1 Like

The message I get in the message variable:
´´´
var message = jsonDecode(response.body);
´´´
is:

{code: 500, description: MessageBodyReader not found for media type=application/json, type=class io.jsonwebtoken.impl.DefaultClaims, genericType=class io.jsonwebtoken.impl.DefaultClaims.}

Hi again,

Thank you for waiting, we are currently troubleshooting your problem.

I will reach back to you again before 15:00 central european time with an update on our progress.

Best regards
Pontus

Hello!

Could you try running this code and check if it works?

Map<String, dynamic> body = {
  "bbox": [13, 45, 14, 46],
  "datetime": "2019-12-10T00:00:00Z/2020-12-15T00:00:00Z",
  "collections": ["sentinel-2-l2a"],
  "limit": 50,
  "distinct": "date"
};

var response = await http.post(
  Uri.https('services.sentinel-hub.com', '/api/v1/catalog/search'), 
  headers: {
    'Authorization': 'Bearer <Your Access Token Here> ',
    'Content-Type': 'application/json',
  },
  body: json.encode(body),
);

var decoded = jsonDecode(response.body);
debugPrint('response: $decoded');

Hello, still has the same error. I tried to Post on the postman website and continue the same error too.

“code”: 500,

“description”: “MessageBodyReader not found for media type=application/json, type=class io.jsonwebtoken.impl.DefaultClaims, genericType=class io.jsonwebtoken.impl.DefaultClaims.”.

Okay!

Could you try to create a new Client ID/Secret on the Sentinel Hub dashboard and generate a new authentication token from it?

Hello. Still the same situation :frowning: I am using a trial period. Is the service really working?

Could you send me a private message here on the forum where you show what your Authorization part looks when you send the request?

This one:
'Authorization': 'Bearer <your access token>

1 Like