【问题标题】:hubspot integration with nodejshubspot 与 nodejs 的集成
【发布时间】:2019-02-11 11:43:53
【问题描述】:

我正在尝试将 Hubspot 表单与 nodejs 连接,但给了我一个错误。我在本地服务器和远程 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

【问题讨论】:

标签: node.js forms api integration hubspot


【解决方案1】:

尝试使用this library 而不是使用原始 API - 它一直对我们有用。如果仍然无法正常工作,请尝试按照this SO question 中的答案中的说明添加调试。

【讨论】:

    猜你喜欢
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 2017-11-05
    • 1970-01-01
    • 2017-10-14
    • 2018-11-14
    相关资源
    最近更新 更多