Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查API中节点是否存在电子邮件_Javascript_Node.js_Api_Post_Xmlhttprequest - Fatal编程技术网

Javascript 检查API中节点是否存在电子邮件

Javascript 检查API中节点是否存在电子邮件,javascript,node.js,api,post,xmlhttprequest,Javascript,Node.js,Api,Post,Xmlhttprequest,导言 好的,我有三个功能。前两个为第三个生成数据 获取帖子数据(电子邮件) 获取API密钥 使用API密钥、用户密钥和电子邮件并将它们发布到API 我需要什么 我需要第三个打印以下到我的控制台提供电子邮件存在 else { console.log("Login successful !"); console.log("API Key", api); console.log("

导言

好的,我有三个功能。前两个为第三个生成数据

  • 获取帖子数据(电子邮件)
  • 获取API密钥
  • 使用API密钥、用户密钥和电子邮件并将它们发布到API
  • 我需要什么

    我需要第三个打印以下到我的控制台提供电子邮件存在

     else {
                        console.log("Login successful !");
                        console.log("API Key", api);
                        console.log("userKey", userkey);
                        console.log("useremail", login_email);
                        console.error("Third You have logged in !");
                    }
    
    我得到的

    错误空值

    即使我发布了一封存在的电子邮件,我还是收到了这封邮件。有人看到我的代码哪里出错了吗

    节点代码

    var firstFunction = function () {
        var promise = new Promise(function (resolve) { // may be redundant
            setTimeout(function () {
                app.post('/test.js', function (req, res) {
                    console.log(req.body);
                    // Get varibles from the post form
                    var login = req.body.LoginEmail;
                    // res.send(email_user);
                    res.send(login);
                    //resolve when get the response
                    resolve({
                        data_login_email: login
                    });
                });
                console.error("First done");
    
            }, 2000);
        });
        return promise;
    };
    
    //---------------------------------- Function to get API key from Pardot (AUTHENTICATION) ------------------------------
    //----------------------------------------------------------------------------------------------------------------------
    var secondFunction = function () {
        var promise = new Promise(function (resolve) {
            setTimeout(function () {
                nodePardot.PardotAPI({
                    userKey: userkey,
                    email: emailAdmin,
                    password: password,
                    DEBUG: false
                }, function (err, client) {
                    if (err) {
                        // Authentication failed
                        console.error("Authentication Failed", err);
                    } else {
                        // Authentication successful
                        var api_key = client.apiKey;
                        console.log("Authentication successful !", api_key);
                        resolve({data_api: api_key});
                    }
                });
                console.error("Second done");
            }, 2000);
        });
        return promise;
    };
    
    //---------------------------------- Function to post data to Pardot ---------------------------------------------------
    // ---------------------------------------------------------------------------------------------------------------------
    function thirdFunction(result) {
        var promise = new Promise(function () {
            setTimeout(function () {
                var headers = {
                    'User-Agent': 'Super Agent/0.0.1',
                    'Content-Type': 'application/x-www-form-urlencoded'
                };
    // Configure the request
                var api = result[1].data_api;
                var userEmail = result[0].data_login_email;
                var options = {
                    url: 'https://pi.pardot.com/api/prospect/version/4/do/read',
                    method: 'POST',
                    headers: headers,
                    form: {
                        'email': userEmail,
                        'user_key': userkey,
                        'api_key': api
                    }
                };
    
    // Start the request
                request(options, function (error, response) {
                    if (!error && response.statusCode == 200) {
                        console.log("error", error);
                    }
                    else {
                        console.log("Login successful !");
                        console.log("API Key", api);
                        console.log("userKey", userkey);
                        console.log("useremail", login_email);
                        console.error("Third You have logged in !");
                    }
                });
            }, 3000);
        });
        return promise;
    }
    
    // sequence of functions
    Promise.all([firstFunction(), secondFunction()])
        .then(thirdFunction);
    

    您的if条件是错误的
    (!error&&response.statusCode==200)
    应该是:如果有错误或状态不是200,那么
    error | | response.statusCode=200
    很好,我现在加上这个谢谢