createRelationship method

Future<TableRelationshipResponse> createRelationship({
  1. required String tableId,
  2. required TableIdRelationshipRequest request,
  3. String? authorization,
  4. String? userAgent,
})

Create a relationship

Creates a relationship in a table as well as lookup/summary fields. Relationships can only be created for tables within the same app.

Implementation

Future<TableRelationshipResponse> createRelationship({
  required String tableId, required TableIdRelationshipRequest request,
  String? authorization, String? userAgent }) async {

  Map<String, String> headers = {
    "Authorization": authorization ?? appAuthorization,
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',
    "QB-Realm-Hostname": qBRealmHostname,
    "User-Agent": userAgent?? ""

  };

  Uri endpoint = Uri.https(
      baseUrl, "v1/tables/$tableId/relationship");

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);

  if (response.statusCode >= 400) {
    throw ApiException(response.statusCode, response.body);
  }
  else if (response.statusCode == 200) {
    return TableRelationshipResponse.fromJson(jsonDecode(response.body));
  }
  else {
    throw ApiException(response.statusCode, response.body);
  }

}