Search code examples
pythonapiadditionmembertrello

Is there a way to use the Python API for Trello to invite members to a board?


When reviewing the abilities of the Python API for Trello and considering its functionalities, I was searching for a function that allows to add a member to a board - w./o. success.

What I have tried to use is the following:

trello = TrelloAPI(myAPIKey, myToken)
boardID = myBoardID
fields = {"fullName": "Robo Member",
          "email" : myMail}

trello.boards.get_membersInvited(board_id = boardID, 
                                   fields = fields)

This is how the method implementation looks like:

   def get_membersInvited(self, board_id, fields=None):
    resp = requests.get("https://trello.com/1/boards/%s/membersInvited" % 
    (board_id), params=dict(key=self._apikey, token=self._token, 
    fields=fields), data=None)
    resp.raise_for_status()
    return json.loads(resp.content)

I end up receiving 404 Client Error URL not found. Do you have any suggestions on what to adjust?

Maybe, I used the wrong field names (email and fullName)?

Here is a solution for .NET


Solution

  • Found a remedy by myself. Source --> Trello API Board Put Member

    Here my own solution:

        def invite_new_member(self, fullName, email, boardID):
        url = self.baseURL + "boards/" + boardID + "/members"
        querystring = {"email": email, "key": apikey,
                       "token": token}
        payload = "{\"fullName\":\"" + fullName + "\"}"
        headers = {
            'type': "normal",
            'content-type': "application/json" }
    
        response = requests.request("PUT", url, data=payload, headers=headers, 
        params=querystring)