//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Find relationship from source to target
* 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](https://confluence.atlassian.com/x/_AozKw) required**:
Permission to view both the target entity and source entity.
*/
export async function main(
auth: Confluence,
relationName: string,
sourceType: 'user' | 'content' | 'space',
sourceKey: string,
targetType: 'user' | 'content' | 'space',
targetKey: string,
sourceStatus: string | undefined,
targetStatus: string | undefined,
sourceVersion: string | undefined,
targetVersion: string | undefined,
expand: string | undefined
) {
const url = new URL(
`https://${auth.domain}/wiki/rest/api/relation/${relationName}/from/${sourceType}/${sourceKey}/to/${targetType}/${targetKey}`
)
for (const [k, v] of [
['sourceStatus', sourceStatus],
['targetStatus', targetStatus],
['sourceVersion', sourceVersion],
['targetVersion', targetVersion],
['expand', expand]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago