marth141
11/13/2023, 9:20 PMraghav
11/13/2023, 9:23 PMmarth141
11/13/2023, 9:25 PMSyntaxError: Unexpected end of JSON input [at JSON.parse (native), at Function.get_list_of_employees
And I know that it's just a very big json.marth141
11/13/2023, 9:25 PMWatz
11/13/2023, 9:27 PMeblackey
11/13/2023, 9:28 PMmarth141
11/13/2023, 9:29 PM/**
* @author Nathan Casados
* @NApiVersion 2.1
* @NScriptType MapReduceScript
* @description This is for working through Paylocity employees and setting fieldaware fields on the employee record.
*/
define(['N/https', 'N/log', 'N/runtime', 'N/encode'], function (nhttps, nlog, nruntime, encode) {
function getInputData() {
return PaylocityApi.get_list_of_employees()
}
function map({ value }) {
nlog.debug({ title: "debug", details: value })
}
class PaylocityApi {
static get_list_of_employees() {
const access_token = this.get_paylocity_access_token()
const resp = nhttps.get({
url: "<https://apisandbox.paylocity.com/api/v2/companies/S2222/employees?pagesize=500&pagenumber=0&includetotalcount=true>",
headers: {
"Authorization": `Bearer ${access_token}`,
}
})
const list_of_employees = JSON.parse(resp.body)
return list_of_employees
}
static get_paylocity_access_token() {
const paylocity_client_id = nruntime.getCurrentScript().getParameter({ name: "paylocity_client_id" })
const paylocity_client_secret = nruntime.getCurrentScript().getParameter({ name: "paylocity_client_secret" })
const encoded_auth_token = encode.convert({
string: `${paylocity_client_id}:${paylocity_client_secret}`,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
})
const resp = <http://nhttps.post|nhttps.post>({
url: "<https://apisandbox.paylocity.com/IdentityServer/connect/token>",
headers: {
"Authorization": `Basic ${encoded_auth_token}`,
"Content-Type": "application/x-www-form-urlencoded"
},
body: "grant_type=client_credentials&scope=WebLinkAPI"
})
const { access_token } = JSON.parse(resp.body)
return access_token
}
}
return { getInputData, map }
})
marth141
11/13/2023, 9:29 PMmarth141
11/13/2023, 9:35 PMeblackey
11/13/2023, 9:36 PMeblackey
11/13/2023, 9:37 PMmarth141
11/16/2023, 6:34 PM