Running an API Call from Custom Action

Database & APIs
Resolved

Hello,

I've defined an "API Call" within the FlutterFlow interface, and I've been seeking ways to invoke it from a custom action, particularly an interceptor.

Unfortunately, I haven't found any documentation on this topic.

After some trial and error, I managed to make it work. Below is my code, in the hope that it might assist others.

What have you tried so far?

The import header:

// Although this file exists, the analyzer may generate an error
// due to its dynamic generation. It will be resolved later at compilation.
// To suppress the error during analysis, use the // ignore directive below
// (Personally, I prefer not using the directive)
// ignore: uri_does_not_exist
import '/backend/api_requests/api_calls.dart';

The code:

String myCollectionName = 'Employee';
int myObjectId = 1;
String myFieldName = 'firstname';
String myValue = 'John';

// Run an "API Call" named "api Update Object" 
// as defined and tested in the FlutterFlow interface
// The coded object will be renamed using CamelCase with the Call suffix
// There may be a "not found" error due to the import above,
// but it will be resolved after the app is fully compiled.
var apiCallResult = await ApiUpdateObjectCall.call(
  collectionName: myCollectionName,
  objectId: myObjectId,
  fieldName: myFieldName,
  value: myValue,
);

if (apiCallResult?.succeeded ?? true) {
  // This is a success
} else {
  // We got an error
}
Did you check FlutterFlow's Documentation for this topic?
Yes
9
3 replies