Search code examples
gitwebhookstrello

How to add unique integer short ID (feature number) for every card in trello?


I wrote a web-script, which generates feature number for trello card ID and saves it in a database.

I also created a webhook, which is executed when the trello board changes

When I create a card, the webhook sends a request to callbackURL, but the request doesn't contains data about event. It contains only model information (about board). How do I get ID of new card?

{
    "model"=>{
        "id"=>"5204523d8d3432ff1a000a60",
        "name"=>"#BOARD",
        "desc"=>"",
        "descData"=>nil,
        "closed"=>false,
        "idOrganization"=>"53aaf6e5309dc12a75111fbf",
        "pinned"=>false,
        "url"=>"https://trello.com/b/ABdAaJeO/board",
        "shortUrl"=>"https://trello.com/b/ABdAaJeO",
        "prefs"=>{
            "permissionLevel"=>"org",
            "voting"=>"disabled",
            "comments"=>"members",
            "invitations"=>"members",
            "selfJoin"=>false,
            "cardCovers"=>true,
            "calendarFeedEnabled"=>true,
            "background"=>"river",
            "backgroundColor"=>nil,
            "backgroundImage"=>"https://d2a2fgsv6pobq6.cloudfront.net/images/backgrounds/river/full.jpg",
            "backgroundImageScaled"=>[
                {
                    "width"=>2400,
                    "height"=>1600,
                    "url"=>"https://d2a2fgsv6pobq6.cloudfront.net/images/backgrounds/river/large.jpg"
                },
                {
                    "width"=>1024,
                    "height"=>683,
                    "url"=>"https://d2a2fgsv6pobq6.cloudfront.net/images/backgrounds/river/medium.jpg"
                },
                {
                    "width"=>320,
                    "height"=>213,
                    "url"=>"https://d2a2fgsv6pobq6.cloudfront.net/images/backgrounds/river/small.jpg"
                }
            ],
            "backgroundTile"=>false,
            "backgroundBrightness"=>"dark",
            "canBePublic"=>true,
            "canBeOrg"=>true,
            "canBePrivate"=>true,
            "canInvite"=>true
        },
        "labelNames"=>{
            "green"=>"",
            "yellow"=>"Тесты",
            "orange"=>"frontend",
            "red"=>"bugs",
            "purple"=>"инфраструктура",
            "blue"=>"backend",
            "sky"=>"проектирование",
            "lime"=>"гипотеза",
            "pink"=>"",
            "black"=>""
        }
    },
    "feature"=>{

    }
}

P.S. We use Scrum and now use Trello for it. For every feature we create one card in trello. We create git branches with prefix, containing feature number (f231_feature etc.). When i push changes, i want to automatic add comment to trello card.

We use integer numbers for for every features, but trello card ID is too long and we can't use its. Trello card has integer code (etc. 231 in URL https://trello.com/c/2zrZE33/231-trello), but these codes unique within one board and it not for us, because we move completed cards to other board.


Solution

  • I receive answer from Trello Team:

    If your webhook is set up to watch a board as its model, then you should receive a the following info on your webhook POST:

     "card": {
                    "shortLink": "wKiG3zv8",
                    "idShort": 42,
                    "name": "I'm a new card",
                    "id": "55478b893a73ba2e400381c6"
                }
    

    In that case, the shortLink option is the best way to save a feature number for Trello—by going to https://www.trello.com/c/[the value of shortLink], you can pull up the card. Alternatively, you can use the card's full "id", also provided in that POST. Either option works as a unique identifier for the card within Trello.

    That information is contained in the "data" array, not the "model" array. For information about the action that's been taken, that's going to be the best place to look.

    I check my script and found error. Trello webhook POST request really send not just model object but action information, including information on the new card.