createRelationship method

Future<Relation> createRelationship({
  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,
})

Creates a relationship between two entities (user, space, content). The 'favourite' relationship is supported by default, but you can use this method to create any type of relationship between two entities.

For example, the following method creates a 'sibling' relationship between two pieces of content: GET /wiki/rest/api/relation/sibling/from/content/123/to/content/456

Permissions required: Permission to access the Confluence site ('Can use' global permission).

Implementation

Future<Relation> createRelationship(
    {required String relationName,
    required String sourceType,
    required String sourceKey,
    required String targetType,
    required String targetKey,
    String? sourceStatus,
    String? targetStatus,
    int? sourceVersion,
    int? targetVersion}) async {
  return Relation.fromJson(await _client.send(
    'put',
    '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',
    },
  ));
}