簡體   English   中英

與Node.js的Hubspot集成

[英]hubspot integration with nodejs

我正在嘗試將Hubspot Form與Node.js連接起來,這給了我一個錯誤。 我已經在本地服務器以及遠程heroku服務器上進行了測試。 這是我的代碼。

app.post('/contact', (req, res) => {
    //require Node modules
    var https = require('https')
    var querystring = require('querystring')

    // global variables
    const HUB_ID = "My_HUB_ID";
    const FORM_GUID = "MY_FORM_ID";

    var postData = querystring.stringify({
        'email': "test@gmail.com",
        'firstname': "Test User",
        'phone': "03001234567",
        'message': "Hello World!!!",
        'hs_context': JSON.stringify({
            "hutk": '',
            "ipAddress": req.headers['x-forwarded-for'] || req.connection.remoteAddress,
            "pageUrl": "/contact",
            "pageName": "Contact"
        })
    })

    var options = {
        hostname: 'forms.hubspot.com',
        path: '/uploads/form/v2/' + HUB_ID + '/' + FORM_GUID,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': postData.length
        }
    }

    var request = https.request(options, function(response){
        console.log("Status: " + response.statusCode)
        console.log("Headers: " + JSON.stringify(response.headers))
        response.setEncoding('utf8')
        response.on('data', function(chunk){
            console.log('Body: ' + chunk)
        });
    });

    request.on('error', function(e){
        console.log("Problem with request " + e.message)
    });

    // post the data
    request.end();

    res.json({"message": "Welcome to Bazaristan E-Commerce Online web portal"});
});

有趣的部分在php中測試了此代碼,並且工作正常。 我收到以下錯誤:

請求出現問題錯誤:讀取ECONNRESET

嘗試使用此庫,而不使用原始API-它一直對我們有用。 如果仍然無法解決問題 ,請嘗試按照此SO問題的答案中所述添加調試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM