0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

トレロのAPIでカスタムフィールドの値を更新する!【GAS】

Posted at

GOOGLEフォームから送信された内容をトレロのカスタムフィールドに反映したい!

問題とやりたいこと

  • Googleフォームから送信した内容をAPIを使いトレロのカードに入力する=よくあるやつ
    • これ自体は結構簡単!
    • ただ、リファレンス見ても、カスタムフィールドを更新する方法が良い感じに書いてない。
  • なので本稿はそのためのコードのメモ

使うエンドポイント

https://api.trello.com/1/cards/[cardId]/customField/[customFieldId]/item

用意するもの

  • カードID
  • カスタムフィールドID

これ取得するのは結構簡単なので省略。

実際のコード


function updateCustomFields() {

//認証系
var api_key = "自分のAPI鍵";
var api_token = "自分のAPIトークン";

//エンドポイント周り
var cardId = "任意のカードID";
var fieldId = "任意のカスタムフィールドID";

var url = "https://api.trello.com/1/cards/"+cardId+"/customField/"+fieldId+"/item?key=" + api_key + "&token=" + api_token + "&fields=name";
var data = {
  "value": {
 //ここにカスタムフィールドに入れたい値とか入れる。textじゃないパターンもあるけど、とりあえずテキストにしてある=任意なので自分で変えて
    "text": "任意のテキスト"
   }};

   var params = {
    "method" : "put", //GETではなくPUT
    "contentType" : "application/json", //データ形式の指定
    "payload" : JSON.stringify(data), //JSONで渡す
    muteHttpExceptions : true //おまじない
  };

  const response_customFIelds = UrlFetchApp.fetch(url, params);
}

おわり

だいたいこんな感じ

だいたいこんな感じで動く。本題のフォーム送信して云々は省いたフォーム送信したentryから適当に値抜いてきて、valueに入れといたらよい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?