简体   繁体   English

如何使用Axios发布到Monday API?

[英]How to post to Monday API using Axios?

I'm using Axios to post data to Monday API from a react app. 我正在使用Axios将数据从react应用程序发布到Monday API。

You'll find the dev page on Monday here: https://developers.monday.com/#!/boards/POST_version_boards_board_id_pulses_format 您将在星期一在以下位置找到开发页面: https : //developers.monday.com/#!/boards/POST_version_boards_board_id_pulses_format

Here is my code: 这是我的代码:

 function postForm() { axios.post('https://api.monday.com:443/v1/boards/MY_BOARD/pulses.json?api_key=MY_API_KEY', { name: "Jonathan" }) .then(function(response) { console.log(response); }) .catch(function(error) { console.log(error); }); } 

I get status code 400 on this code. 我在此代码上得到状态码400。 How to config the axios post method correct? 如何正确配置axios post方法?

In the doc 3 parameters are flagged as required. 在doc 3中,根据需要标记了参数。

-board_id which you provide in the url 您在网址中提供的-board_id

-user_id which you should provide in the request's body -user_id,您应该在请求的正文中提供

-pulse[name] which you should also provide in the request's body -pulse [name],您还应该在请求的正文中提供它

You are getting a http 400 because you're not providing those requested params (user_id and pulse[name]). 由于未提供所请求的参数(user_id和pulse [name]),因此获得http 400。

pulse[name] is the name of the new pulse you are trying to create and user_id should be an integer (you'll have to figure Jonathan's id if you want him to be the pulse's owner) pulse [name]是您要创建的新脉冲的名称,user_id应该为整数(如果要让他成为Pulse的所有者,则必须计算Jonathan的ID)

it should look like this : 它应该看起来像这样:

function postForm() {
  axios.post('https://api.monday.com:443/v1/boards/MY_BOARD/pulses.json?api_key=MY_API_KEY', {
  user_id: 0, 
  pulse: {
      name: "Jonathan's pulse"
  }
})
.then(function(response) {
  console.log(response);
})
.catch(function(error) {
  console.log(error);
});

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM