如何从addCard trello API创建trello卡后捕获该卡的链接

How to capture link of a trello card after creating it from addCard trello API?

本文关键字:trello 链接 创建 addCard API      更新时间:2023-09-26

我正在用JS函数在trello板中创建一张新卡

var currentLocation = window.location.href;
function AddCardToTrello() {
  Trello.addCard({
  url: currentLocation,
  name: "{{ soproduct.product }}",
  due: {{ soproduct.required_date|date:"SHORT_DATE_FORMAT"  }}
});
}

创建后,我得到了一个Trello向导,它会向我显示Trello板上新创建的卡的链接。我想捕捉这个链接并将其保存在我的背上。我该怎么做?是否可以从相同的API调用中捕获数据?

我刚刚在Trello Sandbox上测试了这个:

var destinationList = "XX_YOUR_LIST_ID_XX";
var success = function(successMsg) {
  asyncOutput(successMsg);
};
var error = function(errorMsg) {
  asyncOutput(errorMsg);
};
var newCard = 
  {name: "I just created a new card!", 
  desc: "Using the Trello API is fun and easy!",
  pos: "top", 
  due: null,
  idList: destinationList
  };
Trello.post('/cards/', newCard, success, error);

successMsg回调值在对象中包含一个参数:

"url": "https://trello.com/c/PCJcEkmm/6-i-just-created-a-new-card"

因此,我的建议是将保存到后端的过程添加到您的成功函数中——这取决于您使用的插件/脚本架构。

var success = function(successMsg) {
  console.log(successMsg);
  //Save to storage here
};
var error = function(errorMsg) {
  console.log(errorMsg);
};
function AddCardToTrello() {
  Trello.addCard({
  url: currentLocation,
  name: "{{ soproduct.product }}",
  due: {{ soproduct.required_date|date:"SHORT_DATE_FORMAT"  }}
}, success, error);
}