Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

Why won't this Trello API work to post a new card? [closed]

Asked by 9 years ago

I'm not really good with APIs and HttpService and stuff, but why won't this make a card on Trello?

Part that I think I should make:

local BoardID = T:GetBoardID("SoS / SPD / SFD Control Board")
local ListID = T:GetListID("Test Board",BoardID)

game.Players.PlayerAdded:connect(function(Player)
    T:AddCard(Player.Name,"Joined",ListID,1)
end)

Entire Script:

(MODULE SCRIPT)

local Private=false
local addon
local HS=game:GetService("HttpService")
local T = {}
function getAddon()
    if script.Token.Value~="" then
        addon="?key=_______________&token="..script.Token.Value
    else
        error([[-Instructions
     \n 1. Go to this link and click allow: https://trello.com/1/authorize?key=________________6&name=Roblox+Api&expiration=30days&response_type=token&scope=read,write 
     \n 2. Copy the token in the page sent to you
     \n 3. Paste the token in the Value of Token]])
    end
end
--[[
    POST /1/cards/[card id or shortlink]/actions/comments
    Required permissions: comments
    Arguments
    text (required)
        Valid Values: a string with a length from 1 to 16384
--]]
function T:PostComment(cid,t)
                local url
            if Private then
                getAddon()
                url="https://api.trello.com/1/cards/"..tostring(cid).."/actions/comments"..addon
            else
                 url="https://api.trello.com/1/cards/"..tostring(cid).."/actions/comments"
            end
            local dat={
                text=t
            }
            local data=HS:JSONEncode(dat)
            local re=HS:PostAsync(url,data)
            local red=HS:JSONDecode(re)
            return red
end
--/1/lists/[idList]/cards
--[[
    [{
    "id": "4eea503791e31d1746000080",
    "checkItemStates": [],
    "closed": false,
    "dateLastActivity": "2011-12-15T19:53:27.228Z",
    "desc": "",
    "descData": null,
    "email": null,
    "idAttachmentCover": null,
    "idBoard": "4eea4ffc91e31d1746000046",
    "idLabels": [],
    "idList": "4eea4ffc91e31d174600004a",
    "idMembersVoted": [],
    "idShort": 3,
    "manualCoverAttachment": false,
    "name": "Finish my awesome application",
    "pos": 65536,
    "shortLink": "XlG8S7ll",
    "badges": {
        "votes": 0,
        "viewingMemberVoted": false,
        "subscribed": false,
        "fogbugz": "",
        "checkItems": 0,
        "checkItemsChecked": 0,
        "comments": 0,
        "attachments": 0,
        "description": false,
        "due": null
    },
    "due": null,
    "idChecklists": [],
    "idMembers": [],
    "labels": [],
    "shortUrl": "https://trello.com/c/XlG8S7ll",
    "subscribed": false,
    "url": "https://trello.com/c/XlG8S7ll/3-finish-my-awesome-application"
}]
--]]
     function T:GetCardsInList(lid)
            local url
            if Private then
                getAddon()
                url="https://api.trello.com/1/lists/"..tostring(lid).."/cards"..addon
            else
                 url="https://api.trello.com/1/lists/"..tostring(lid).."/cards"
            end
            local re=HS:GetAsync(url,true)
            local dat=HS:JSONDecode(re)
        return dat
    end
    function T:GetCardID(name,boardid)
        local url
        if Private then
            getAddon()
            url="https://api.trello.com/1/boards/"..boardid.."/cards"..addon
        else
             url="https://api.trello.com/1/boards/"..boardid.."/cards"
        end
        local tab=HS:GetAsync(url,true)
        local tabl=HS:JSONDecode(tab)
        for k,ta in pairs(tabl) do
            for p,t in pairs(ta) do
                if p=="name" and t==name then
                    return ta.id
                end
            end
        end
    end
    function T:GetLists(boardid)
        local url
        if Private then
            getAddon()
            url="https://api.trello.com/1/members/my/boards/"..boardid.."/lists"..addon
        else
            url="https://api.trello.com/1/members/my/boards/"..boardid.."/lists"
        end
        local re=HS:GetAsync(url,true)
        local data=HS:JSONDecode(re)
        return data
    end
    function T:GetBoardID(name)
            local url
            if Private then
                getAddon()
                url="https://api.trello.com/1/members/my/boards"..addon
            else
                url="https://api.trello.com/1/members/my/boards"
            end
            local tball=HS:GetAsync(url,true)
            local dt=HS:JSONDecode(tball)
            for _,tab in pairs(dt) do
                for p,it in pairs(tab) do
                    if p=="name" and it==name then
                        return tab.id
                    end
                end
            end
            error(name.." not found!")
            return nil
        end
    --[[
POST /1/cards
    Required permissions: write
    Arguments
    name (optional)
        Valid Values: The name of the new card. It isn't required if the name is being copied from provided by a URL, file or card that is being copied.
    desc (optional)
        Valid Values: a string with a length from 0 to 16384
    pos (optional)
        Default: bottom
        Valid Values: A position. top, bottom, or a positive number.
    due (required)
        Valid Values: A date, or null
    labels (optional)
        Valid Values: all or a comma-separated list of:
        blue
        green
        orange
        purple
        red
        yellow
    idList (required)
        Valid Values: id of the list that the card should be added to
    idMembers (optional)
        Valid Values: A comma-separated list of objectIds, 24-character hex strings
    idLabels (optional)
        Valid Values: A comma-separated list of objectIds, 24-character hex strings
    urlSource (required)
        Valid Values: A URL starting with http:// or https:// or null
    fileSource (optional)
        Valid Values: A file
    idCardSource (optional)
        Valid Values: The id of the card to copy into a new card.
    keepFromSource (optional)
        Default: all
        Valid Values: Properties of the card to copy over from the source.

    --]]
    function T:AddCard(...)
        local url
        local args={...}
        local dat
        if #args==3 then
            local nam,des,lid=args[1],args[2],args[3]
            dat={
            name=nam,
            desc=des.."",
            idList=lid,
            urlSource=nil,
            due=nil
            }
        elseif #args==4 then
            local nam,des,lid,url=args[1],args[2],args[3],args[4]
            dat={
            name=nam,
            desc=""..des,
            idList=lid,
            urlSource=url,
            due=nil
            }
        elseif #args==5 then
            local nam,des,lid,url,po=args[1],args[2],args[3],args[4],args[5]
            dat={
            name=nam,
            desc=""..des,
            idList=lid,
            urlSource=url,
            pos=po,
            due=nil
            }
        elseif #args==6 then
            local nam,des,lid,url,po,de=args[1],args[2],args[3],args[4],args[5],args[6]
            dat={
            name=nam,
            desc=""..des,
            idList=lid,
            urlSource=url,
            pos=po,
            due=de
            }
        elseif #args==7 then
            local nam,des,lid,url,po,de,label=args[1],args[2],args[3],args[4],args[5],args[6],args[7]
            dat={
            name=nam,
            desc=""..des,
            idList=lid,
            urlSource=url,
            pos=po,
            due=de,
            labels=label
            }
        elseif #args==8 then
            local nam,des,lid,url,po,de,label,cc=args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]
            dat={
            name=nam,
            desc=""..des,
            idList=lid,
            urlSource=url,
            pos=po,
            due=de,
            labels=label,
            idCardSource=cc
            }
        end
        local data=HS:JSONEncode(dat)
        if Private then
            getAddon()
            url="https://api.trello.com/1/cards"..addon
        else
             url="https://api.trello.com/1/cards"
        end
        local re=HS:PostAsync(url,data)
        return HS:JSONDecode(re)
    end

    function T:GetListID(name,boardid)
        local url
        if Private then
            getAddon()
            url="https://api.trello.com/1/boards/"..boardid.."/lists"..addon
        else
             url="https://api.trello.com/1/boards/"..boardid.."/lists"
        end
        local tab=HS:GetAsync(url,true)
        local tabl=HS:JSONDecode(tab)
        for k,ta in pairs(tabl) do
            for p,t in pairs(ta) do
                if p=="name" and t==name then
                    return ta.id
                end
            end
        end
    end
    function T:AddList(...)
        local args={...}
        local nam,boid,idsource,po
        local url
        local dat
        if #args==2 then
            nam,boid=args[1],args[2]
            dat={name=nam,idBoard=boid}
        elseif #args==3 then
            nam,boid,idsource=args[1],args[2],args[3]
            dat={name=nam,idBoard=boid,idListSource=idsource}
        elseif #args==4 then
            nam,boid,idsource,po=args[1],args[2],args[3],args[4]
            dat={name=nam,idBoard=boid,idListSource=idsource,pos=po}
        else
            error("Invalid arguments: "..table.concat(args,","))
        end
        --  
        if Private then
            getAddon()
            url="https://api.trello.com/1/lists"..addon
        else
            url="https://api.trello.com/1/lists"
        end
        local data=HS:JSONEncode(dat)
        local re=HS:PostAsync(url,data)
        return re.id
    end




local BoardID = T:GetBoardID("SoS / SPD / SFD Control Board")
local ListID = T:GetListID("Test Board",BoardID)

game.Players.PlayerAdded:connect(function(Player)
    T:AddCard(Player.Name,"Joined",ListID,1)
end)

return T
3
DO NOT SHARE PRIVATE KEYS! I have taken the liberty of removing 4 characters from it (which does not at all keep it safe), but you should NOT share it publicly. Apologies if I have misunderstood that those keys aren't private.  BlueTaslem 18071 — 9y
2
REMOVE THIS POST! DON'T POST YOUR KEY! DigitalVeer 1473 — 9y
0
What Key? TypicalModerator 110 — 9y
2
Your trello key... Do you know how Trello works? A specific key is all that is needed to obtain access to your board. DigitalVeer 1473 — 9y
0
I don't really know how Trello works. I only use it with the Kohl's Epix Admin Edit. TypicalModerator 110 — 9y

Locked by TheeDeathCaster, SanityMan, and FearMeIAmLag

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?