Node Js, получить данные из API - PullRequest
0 голосов
/ 26 мая 2020

Я пытаюсь получить данные из API Veryfi с помощью Node Js в функции firebase. Но когда я отправляю запрос на получение из почтальона, я получаю следующую ошибку:

2020-05-26T14:38:13.052Z E getAllProcessedDocuments: TypeError: "listener" argument must be a function
    at ClientRequest.once (events.js:340:11)
    at new ClientRequest (_http_client.js:174:10)
    at Object.request (http.js:39:10)
    at Object.request (https.js:245:15)
    at Object.get (https.js:249:21)
    at exports.getAllProcessedDocuments.functions.https.onRequest (/srv/index.js:144:11)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:16)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at _combinedTickCallback (internal/process/next_tick.js:132:7)

Моя функция выглядит так:

exports.getAllProcessedDocuments = functions.https.onRequest((request, response) => {
    console.log(JSON.stringify(response.header));

    var get_options = {
        headers: {
            "Content-Type": "multipart/form-data",
            "Accept": "application/json",
            "CLIENT-ID": "vrf02pnSzhXXXXXXXXXXXwFznuhPffEcTNSl",
            "AUTHORIZATION": "apikey yanXXck.tXXXen:6b2XXXXXXXXXXXXXXXXX65ff24248"
        }
    };

    https.get('https://api.veryfi.com/api/v7/partner/documents/', get_options, (resp) => {
        let data = '';

        // A chunk of data has been recieved.
        resp.on('data', (chunk) => {
            data += chunk;
        });

        // The whole response has been received. Print out the result.
        resp.on('end', () => {
          //  console.log(JSON.parse(data).explanation);
            return response.sendStatus(200);
        });
    }).on("error", (err) => {
        console.log("Error: " + err.message);
        return response.sendStatus(404);
    });
});

У кого-нибудь есть идея?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...