Skip to main content

Curl Post method Sentinel on Flutter

  • April 17, 2024
  • 14 replies
  • 0 views

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 🙂

14 replies

Hello!

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

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');

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


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.}


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 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.”.


Hi,
Is this solution 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>


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


Hello!

Let me know if you’re experiencing any problems and I will help you.


Hi, it worked and it is working.


Thanks,
Kenny
I’ll write something like that and test it.
Regards


So, in my project i call the function tapping the button with function onPressed:

onPressed: () async {
      if (parcelas.parcelaPAGAMENTOSTATUS == 1 || trialStatus == 1) {
         await loadDateForCalendar(context, parcelas.parcelaCOORDENADAS); 
      }

and here is the function loadDateForCalendar:

loadDateForCalendar(BuildContext context, String coordenadas) async {
      var url = 'https://<yoursite>/auth.php';
      var response3 = await http.post(url);
      var message3 = json.decode(json.encode(response3.body));
      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": 80,
        "distinct": "date"
      };

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

I have a php url to update the acess token with my client Id and client secret.


Hi,
Yes. I have no programming experience, but I have not been successful.
In DartPad:
Error: ‘await’ can only be used in ‘async’ or ‘async*’ methods.