# Unable to get a response from API

**URL:** <https://support.routexl.com/t/unable-to-get-a-response-from-api/2986>\
**Category:** API\
**Created:** [January 14, 2025, 1:36pm UTC](https://support.routexl.com/t/unable-to-get-a-response-from-api/2986 "2025-01-14T13:36:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehan](https://support.routexl.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Mehan](https://support.routexl.com/u/Mehan)\
**Post date:** [January 14, 2025, 1:36pm UTC](https://support.routexl.com/t/unable-to-get-a-response-from-api/2986/1 "2025-01-14T13:36:46Z")

</div>

i made an attempt to connect to your api but we’re not getting a response the below are the codes :

```auto
static Future<dynamic> fetchOptimizedRoute(
      List<DeliveryDayDetailsModel> locations) async {
    const username = 'USERNAME';
    const password = 'PASSWORD';
    const endpoint = 'https://api.routexl.nl/tour/';
    final List<Map<String, dynamic>> locations0 = [
      {"address": "Riyadh", "lat": 24.7136, "lng": 46.6753},
      {"address": "Mecca", "lat": 21.3891, "lng": 39.8579},
      {"address": "Taif", "lat": 21.2854, "lng": 40.6316},
      {"address": "Dammam", "lat": 26.4207, "lng": 50.0888},
    ];
    final response = await http.post(
      Uri.parse(endpoint),
      headers: {
        'Authorization':
            'Basic ${base64Encode(utf8.encode('$username:$password'))}',
        'Content-Type': 'application/json',
      },
      body: jsonEncode({'locations': locations0}),
    );

    if (response.statusCode == 200) {
      final data = jsonDecode(response.body);
      print(data);
      // _drawRoute(data['route'], data['total_distance'], data['total_time']);
    } else {
      print('Error fetching optimized route: ${response.statusCode}');
    }
  }

```

---

<div class="post-metadata">

**Author:** ![RouteXL](https://support.routexl.com/user_avatar/support.routexl.com/routexl/32/347_2.png) [@RouteXL](https://support.routexl.com/u/RouteXL)\
**Post date:** [January 14, 2025, 4:37pm UTC](https://support.routexl.com/t/unable-to-get-a-response-from-api/2986/2 "2025-01-14T16:37:39Z")

</div>

Unfortunately, we’re not experts in your specific programming language, but you may need to adjust how your request body is formatted. It looks like the issue might be related to the content-type header in your request. While your `locations` parameter should indeed be JSON-encoded, the RouteXL API requires the request itself to use `application/x-www-form-urlencoded` as the `Content-Type`.
