0
Delete Post
One script reply has been approved by the moderators Verified

Removes a post from user's wall. See the docs for more information

Created by hugo697 130 days ago Viewed 50 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(resource: Linkedin, postId: string) {
7
	// The URL in script.json points to Legacy API.
8
	const encodedPostId = encodeURIComponent(postId)
9
	const endpoint = `https://api.linkedin.com/rest/posts/${encodedPostId}`
10

11
	const response = await fetch(endpoint, {
12
		method: 'DELETE',
13
		headers: {
14
			Authorization: `Bearer ${resource.token}`,
15
			'X-Restli-Protocol-Version': '2.0.0',
16
			'LinkedIn-Version': `${resource.apiVersion}`
17
		}
18
	})
19

20
	if (!response.ok) {
21
		throw new Error(`HTTP error! status: ${response.status}`)
22
	}
23

24
	const data = await response.json()
25

26
	return data
27
}
28