[SOLVED] Error making API call in support script with Axios: big headers



  • Hello,
    I'm experimenting with calling an external API from a script.
    I have two APIs on a local server: one can be called from JSReport, the other throws a cryptic error.

    const axios = require('axios'); 
     
    async function callApi() {
        return axios.get('http://localhost:8800/api/PING.PING?noblock');
    }
     // add jsreport hook which modifies the report input data
    async function beforeRender(req, res) {
        const r = await callApi();
        console.log("ret is ",r.data)
        req.data = { ...req.data, ...r.data}
    }
    

    while if I change it to a login API with post method:

    const axios = require('axios'); 
     
    async function callApi() { 
        return axios.post('http://localhost:8800/api/REST_ACCOUNT.LOGIN',{
              Usercode:"000000",
              Codice_Concessione:"GG",
              Browser:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36",
               Password:"xxxxxxxxxx",
               Lingua:"POR"
             }
        ); 
    }
    

    i get this error

    2020-09-30T14:35:07.392Z - debug: Executing script prova-script.js using http-server strategy
    2020-09-30T14:35:09.941Z - warn: Rendering request 1 finished with error in 2554 ms
    2020-09-30T14:35:09.941Z - warn: Error when processing render request 1 Parse Error Error: Parse Error
        at Socket.socketOnData (_http_client.js:442:20)
        at Socket.emit (events.js:198:13)
        at Socket.EventEmitter.emit (domain.js:466:23)
        at addChunk (_stream_readable.js:288:12)
        at readableAddChunk (_stream_readable.js:269:11)
        at Socket.Readable.push (_stream_readable.js:224:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:94:17)
    2020-09-30T14:35:09.942Z - warn: Error during processing request at h
    

    I've tested calling the latter API on a browser page with the same Axios code and the params are correct.
    The only unusual things in this API are:

    • return data is a 9K json
    • response headers are pretty big, around 12K because of the JWT token

    Any ideas?
    Thanks



  • Ok, as I suspected the problem was with the huge headers.
    Since the same problem was in Postman, we solved it with the same workaround:

    NODE_OPTIONS=--max-http-header-size=16384 jsreport start
    

    this is the original post [https://github.com/postmanlabs/postman-app-support/issues/8656]


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.