Hey if you're making a get request for say like a ...
# suitescript
m
Hey if you're making a get request for say like a 309kb json response in a MapReduce, how do you get the whole response and not just the first part of the json?
r
Do you mean in the logs ?
m
No I mean in the script. I keep getting an error like this...
SyntaxError: 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.
Thing is I can make the request fine in postman and everywhere else, just not here in my Netsuite script.
w
have you tried saving the response-string as a file in the file cabinet to find out where it is clipping?
e
Can you post the code where you're making the https call?
m
Sure. Should be fine.
Copy code
/**
 * @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 }
})
It's frying at line 23
For reference, I did have a simpler version that was able to get the first record of the list from the JSON while executing in the script debugger.
e
That's odd. It looks fine to me. Couple of thoughts. 1) How large do you expect the response to be? Wondering if you could be tripping some max response size. 2) You might try setting an "Accept" header to "application/json". It could be that the remote server is botching the response.
Maybe check what headers Postman is setting by default on a call that works and try to mimic those in this call.
1
m
I figured it out--my runtime get parameters were misnamed.