0
Create Like On Share
One script reply has been approved by the moderators Verified

Creates a like on a share. See the docs here

Created by hugo697 130 days ago Viewed 49 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 130 days ago
1
type Linkedin = {
2
	token: string
3
	apiVersion: string
4
}
5

6
export async function main(
7
	resource: Linkedin,
8
	activityUrn: string, // can be either Share/Post/Comment Urn
9
	likeData: {
10
		actor: string
11
		object: string
12
	}
13
) {
14
	// Using unversioned API, can replace with versioned one, but cannot test without Marketing access.
15
	const endcodedActivityUrn = encodeURIComponent(activityUrn)
16
	const endpoint = `https://api.linkedin.com/v2/socialActions/${endcodedActivityUrn}/likes`
17

18
	const response = await fetch(endpoint, {
19
		method: 'POST',
20
		headers: {
21
			Authorization: `Bearer ${resource.token}`,
22
			'X-Restli-Protocol-Version': '2.0.0',
23
			'Content-Type': 'application/json'
24
		},
25
		body: JSON.stringify(likeData)
26
	})
27

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

32
	const data = await response.json()
33

34
	return data
35
}
36