【问题标题】:ActiveCampaign axios post request returns 422ActiveCampaign axios post请求返回422
【发布时间】:2020-08-04 05:48:13
【问题描述】:

这是对象和发布请求

let contactObject = {
    contact: {
        email: "jsmith@example.com",
        firstName: "John",
        lastName: "Smith"
    }
};

const options = {
    method: 'POST',
    headers: {
        'Api-Token': `${token}`,
        'content-type': 'application/json',
    },
    data: contactObject,
    url,
};

await axios(options);

这是我得到的回应

   "status": "error",
"error": {
    "message": "Request failed with status code 422",
    "name": "Error",
    "stack": "Error: Request failed with status code 422\n    at createError (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/adapters/http.js:236:11)\n    at IncomingMessage.emit (events.js:215:7)\n    at endReadableNT (_stream_readable.js:1184:12)\n    at processTicksAndRejections (internal/process/task_queues.js:80:21)",
    "config": {
        "url": "https://successroadacademy.api-us1.com/api/3/contacts",
        "method": "post",
        "data": "{\"contact\":{\"email\":\"jsmith@example.com\",\"firstName\":\"John\",\"lastName\":\"Smith\"}}",
        "headers": {
            "Accept": "application/json, text/plain, */*",
            "Content-Type": "application/json",
            "Api-Token": "APITOKEN",
            "User-Agent": "axios/0.19.2",
            "Content-Length": 80
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1
    }
},
"message": "Request failed with status code 422",
"stack": "Error: Request failed with status code 422\n    at createError (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/Users/robert/chatbots/truchat_helper_functions/node_modules/axios/lib/adapters/http.js:236:11)\n    at IncomingMessage.emit (events.js:215:7)\n    at endReadableNT (_stream_readable.js:1184:12)\n    at processTicksAndRejections (internal/process/task_queues.js:80:21)"

}

如果有人知道可能是什么问题,请帮助我尝试了我能想到的一切。并且不知道我如何更改数据对象或标头请求,我总是得到相同的响应。

这是 ActiveCampaign API 的链接

https://developers.activecampaign.com/reference#http-methods

【问题讨论】:

  • 你能围绕 axios 响应做一些调试吗?您提供的内容并未显示响应错误已从 api 返回。 axios(options).then(res => console.log(res)).catch(e => console.log(e.res.data))

标签: javascript node.js axios http-status-code-422 activecampaign


【解决方案1】:

在与 ActiveCampaign 的支持人员交谈后找到了解决方案,这很棒

const email = req.body.email;
const name = req.body.firstName;
const last = req.body.lastName;
const phone = req.body.phone;

let contactObject = {
    "contact": {
        "email": email,
        "firstName": name,
        "lastName": last,
        "phone": phone
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-19
    • 2020-10-26
    • 1970-01-01
    • 2015-11-18
    • 2022-01-05
    • 2018-04-17
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多