0

Create Company Punch Detail Operation

by
Published Oct 17, 2025

**Summary Description** The Company Punch Detail API offers access to comprehensive punch data at the company level.

Script paylocity Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Paylocity = {
3
	clientId: string
4
	clientSecret: string
5
}
6
/**
7
 * Create Company Punch Detail Operation
8
 * **Summary Description**
9

10
The Company Punch Detail API offers access to comprehensive punch data at the company level.
11
 */
12
export async function main(
13
	auth: Paylocity,
14
	companyId: string,
15
	body: { relativeStart?: string; relativeEnd?: string }
16
) {
17
	const url = new URL(
18
		`https://dc1prodgwext.paylocity.com/apiHub/time/v2/companies/${companyId}/punchDetails`
19
	)
20

21
	const response = await fetch(url, {
22
		method: 'POST',
23
		headers: {
24
			'Content-Type': 'application/json',
25
			Authorization:
26
				'Bearer ' +
27
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
28
		},
29
		body: JSON.stringify(body)
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.text()
36
}
37

38
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
39
	const params = new URLSearchParams({
40
		grant_type: 'client_credentials',
41
		client_id: auth.clientId,
42
		client_secret: auth.clientSecret
43
	})
44

45
	const response = await fetch(tokenUrl, {
46
		method: 'POST',
47
		headers: {
48
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
49
			'Content-Type': 'application/x-www-form-urlencoded'
50
		},
51
		body: params.toString()
52
	})
53

54
	if (!response.ok) {
55
		const text = await response.text()
56
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
57
	}
58

59
	const data = await response.json()
60
	return data.access_token
61
}
62