0

Delete relationship

by
Published Oct 17, 2025

Deletes a relationship between two entities (user, space, content). **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to access the Confluence site ('Can use' global permission). For favourite relationships, the current user can only delete their own favourite relationships. A space administrator can delete favourite relationships for any user.

Script confluence
  • Submitted by hugo697 Bun
    Created 284 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Delete relationship
    9
     * Deletes a relationship between two entities (user, space, content).
    10
    
    
    11
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    12
    Permission to access the Confluence site ('Can use' global permission).
    13
    For favourite relationships, the current user can only delete their own
    14
    favourite relationships. A space administrator can delete favourite
    15
    relationships for any user.
    16
     */
    17
    export async function main(
    18
    	auth: Confluence,
    19
    	relationName: string,
    20
    	sourceType: 'user' | 'content' | 'space',
    21
    	sourceKey: string,
    22
    	targetType: 'user' | 'content' | 'space',
    23
    	targetKey: string,
    24
    	sourceStatus: string | undefined,
    25
    	targetStatus: string | undefined,
    26
    	sourceVersion: string | undefined,
    27
    	targetVersion: string | undefined
    28
    ) {
    29
    	const url = new URL(
    30
    		`https://${auth.domain}/wiki/rest/api/relation/${relationName}/from/${sourceType}/${sourceKey}/to/${targetType}/${targetKey}`
    31
    	)
    32
    	for (const [k, v] of [
    33
    		['sourceStatus', sourceStatus],
    34
    		['targetStatus', targetStatus],
    35
    		['sourceVersion', sourceVersion],
    36
    		['targetVersion', targetVersion]
    37
    	]) {
    38
    		if (v !== undefined && v !== '' && k !== undefined) {
    39
    			url.searchParams.append(k, v)
    40
    		}
    41
    	}
    42
    	const response = await fetch(url, {
    43
    		method: 'DELETE',
    44
    		headers: {
    45
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    46
    		},
    47
    		body: undefined
    48
    	})
    49
    	if (!response.ok) {
    50
    		const text = await response.text()
    51
    		throw new Error(`${response.status} ${text}`)
    52
    	}
    53
    	return await response.text()
    54
    }
    55