Retrieves Comments on Comments

Retrieves comments on comments, given the parent comment urn. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#retrieve-comments-on-comments)

Script linkedin Verified

by hugo697 ยท 7/17/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 689 days ago
1
type Linkedin = {
2
	token: string
3
	apiVersion: string
4
}
5

6
export async function main(
7
	resource: Linkedin,
8
	activityUrn: string, // e.g. urn:li:activity:6273189577469632512
9
	commentId: string // e.g. 6275822846992351232
10
) {
11
	const pathParam = `urn:li:comment:(${activityUrn},${commentId})`
12
	// encodeURIComponent does not encode parenthesis, so using replace for that.
13
	const encodedPathParam = encodeURIComponent(pathParam).replace(/\(/g, '%28').replace(/\)/g, '%29')
14

15
	const endpoint = `https://api.linkedin.com/rest/socialActions/${encodedPathParam}/comments`
16

17
	const response = await fetch(endpoint, {
18
		method: 'GET',
19
		headers: {
20
			Authorization: `Bearer ${resource.token}`,
21
			'X-Restli-Protocol-Version': '2.0.0',
22
			'LinkedIn-Version': `${resource.apiVersion}`
23
		}
24
	})
25

26
	if (!response.ok) {
27
		throw new Error(`HTTP error! status: ${response.status}`)
28
	}
29

30
	const data = await response.json()
31

32
	return data
33
}
34