Delete Post

Removes a post from user's wall. [See the docs](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#delete-shares) for more information

Script linkedin Verified

by hugo697 ยท 7/17/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 690 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