Issue with Passing begin Parameter in yyyy-MM-dd+HH:mm:ss Format Using API Interceptor

Database & APIs

Hi everyone,

I’m encountering an issue with passing the begin parameter in the yyyy-MM-dd+HH:mm:ss format in my FlutterFlow project. I am using an API Interceptor to modify the begin parameter before sending the request, but I am facing some difficulties.

• The begin parameter needs to be in the format: 2024-06-30+09:18:44.

• Unfortunately, FlutterFlow sends this parameter in URL-encoded format: 2024-06-21%2B09%3A18%3A44, which is not accepted by API.

• I would like to use an API Interceptor to automatically modify the begin parameter to the correct format before sending the request.

What have you tried so far?

I created an API Interceptor that checks for the presence of the begin parameter and modifies its value. However, I am running into issues related to methods available in ApiCallOptions.

// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import '/backend/api_requests/api_interceptor.dart';

class ExampleInterceptor extends FFApiInterceptor {
  @override
  Future<ApiCallOptions> onRequest({
    required ApiCallOptions options,
  }) async {
    // Check if 'begin' parameter exists
    if (options.params.containsKey('begin')) {
      DateTime date = DateTime.now(); // You can set your specific date here
      // Example: DateTime date = DateTime.parse("2024-06-30 09:18:44");

      String formattedDate = "${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}+${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}:${date.second.toString().padLeft(2, '0')}";

      // Update the 'begin' parameter with the formatted date
      options.params['begin'] = formattedDate;
    }

    return options;
  }

  @override
  Future<ApiCallResponse> onResponse({
    required ApiCallResponse response,
    required Future<ApiCallResponse> Function() retryFn,
  }) async {
    // Perform any necessary calls or modifications to the [response] prior
    // to returning it.
    return response;
  }
}

Issues:

• I am encountering errors related to the lack of copyWith and uri methods in ApiCallOptions.

• Modifying the begin parameter directly on the options.params object doesn’t seem to work correctly.

• Even when setting options.params['begin'] directly, clicking “TEST API” seems to ignore the interceptor as the parameter is not modified.

Did you check FlutterFlow's Documentation for this topic?
Yes
2
1 reply