Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby
require 'trello' # ruby-trello gem
require 'csv'
# export TRELLO_DEVELOPER_PUBLIC_KEY=yourkeyfrom #
# export BOARD_NAME=nameofboardtoimportto
# export MEMBER_NAME=yourusername
# run: ./import_trello_cards filename.csv
class TrelloCardsFromCSV
include Trello
attr_accessor :filename, :board_name, :board, :member_name, :member, :label
# Initialize the object and process the card file
# filename - the relative name of the file to read card data from (must be well-formed CSV)
# board_name - the name of the board to add cards to (comes from an environment variable)
# member_name - the name of the member to add cards as (comes from an environment variable)
# label - the label to apply to created cards (optional, but in this script defaults to 'blue')
def initialize(filename, board_name, member_name, label = nil)
self.filename = filename
self.board_name = board_name
self.member_name = member_name
self.label = label
Trello.configure do |config|
config.developer_public_key = key
token = ENV['TRELLO_MEMBER_TOKEN'] || begin
`open "{key}&name=Trello+Import&expiration=1day&response_type=token&scope=read,write"`
puts "Accept permissions and paste the token in here: "
config.member_token = token
# Find the member to use when looking for boards
self.member = Member.find(self.member_name)
puts "Using member: #{member.inspect}"
# Find the board by it's name
self.board = { |b| == self.board_name }.first
# Stop running the script if a matching board could not be found
raise "No board found" unless board
puts "Using board #{}"
# Assume first list is the one we want to import to
list_id =
puts "Using list #{}"
# Open file and import, headers: true).each do |row|
name = row["name"]
url = "" + row["path"]
speakers = row.fetch("speakers", "").to_s.split(",").map(&:strip).map {|markup| markup.match(/\>(.*)\</)[1]}
# The card will be created with a name such as 001 User Authentication
# and a description which will be whatever is in the final column of the CSV
card = Card.create({
:list_id => list_id,
:name => name + ' == ' + speakers.join(', '),
:description => url
# A card label is applied here if one is passed in - note that 'colors' must be used
# rather than any text applied to the label.
# card.add_label(self.label) if self.label
puts "Imported #{}"
# Set up and run the script, passing in environment variables except for the filename
# , which is passed in from the command, and the label, which is fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment