0

Gets Employee Punch Details

by
Published Oct 17, 2025

**Summary Description** The GET Punch Detail V2 endpoint provides access to employee punch details effortlessly.

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
 * Gets Employee Punch Details
8
 * **Summary Description**
9

10
The GET Punch Detail V2 endpoint provides access to employee punch details effortlessly.
11
 */
12
export async function main(
13
	auth: Paylocity,
14
	companyId: string,
15
	employeeId: string,
16
	relativeStart: string | undefined,
17
	relativeEnd: string | undefined,
18
	testFlag: string | undefined
19
) {
20
	const url = new URL(
21
		`https://dc1prodgwext.paylocity.com/apiHub/time/v2/companies/${companyId}/employees/${employeeId}/punchDetails`
22
	)
23
	for (const [k, v] of [
24
		['relativeStart', relativeStart],
25
		['relativeEnd', relativeEnd],
26
		['testFlag', testFlag]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'GET',
34
		headers: {
35
			Authorization:
36
				'Bearer ' +
37
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
38
		},
39
		body: undefined
40
	})
41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45
	return await response.json()
46
}
47

48
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
49
	const params = new URLSearchParams({
50
		grant_type: 'client_credentials',
51
		client_id: auth.clientId,
52
		client_secret: auth.clientSecret
53
	})
54

55
	const response = await fetch(tokenUrl, {
56
		method: 'POST',
57
		headers: {
58
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
59
			'Content-Type': 'application/x-www-form-urlencoded'
60
		},
61
		body: params.toString()
62
	})
63

64
	if (!response.ok) {
65
		const text = await response.text()
66
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
67
	}
68

69
	const data = await response.json()
70
	return data.access_token
71
}
72