getRelationship method

Future<Relation> getRelationship({
  1. required String relationName,
  2. required String sourceType,
  3. required String sourceKey,
  4. required String targetType,
  5. required String targetKey,
  6. String? sourceStatus,
  7. String? targetStatus,
  8. int? sourceVersion,
  9. int? targetVersion,
  10. List<String>? expand,
})

Find whether a particular type of relationship exists from a source entity to a target entity. Note, relationships are one way.

For example, you can use this method to find whether the current user has selected a particular page as a favorite (i.e. 'save for later'): GET /wiki/rest/api/relation/favourite/from/user/current/to/content/123

Permissions required: Permission to view both the target entity and source entity.

Implementation

Future<Relation> getRelationship(
    {required String relationName,
    required String sourceType,
    required String sourceKey,
    required String targetType,
    required String targetKey,
    String? sourceStatus,
    String? targetStatus,
    int? sourceVersion,
    int? targetVersion,
    List<String>? expand}) async {
  return Relation.fromJson(await _client.send(
    'get',
    'wiki/rest/api/relation/{relationName}/from/{sourceType}/{sourceKey}/to/{targetType}/{targetKey}',
    pathParameters: {
      'relationName': relationName,
      'sourceType': sourceType,
      'sourceKey': sourceKey,
      'targetType': targetType,
      'targetKey': targetKey,
    },
    queryParameters: {
      if (sourceStatus != null) 'sourceStatus': sourceStatus,
      if (targetStatus != null) 'targetStatus': targetStatus,
      if (sourceVersion != null) 'sourceVersion': '$sourceVersion',
      if (targetVersion != null) 'targetVersion': '$targetVersion',
      if (expand != null) 'expand': expand.map((e) => e).join(','),
    },
  ));
}