Trello doesn't move cards between lists using Google App Script
Asked by Sheila Venade:

I think I have try all the solutions around here, and none of them worked for me.

The problem is that I can't move cards between list using the trello api. I have tried this ways to do it:  
Number 1:

```
var API_KEY = '********************************';var TOKEN = '************************************************************';var ID_LIST = '***************************';  var payload = {    "value": ID_LIST,    "token": TOKEN,    "key": API_KEY  };  var options = {    "method": "PUT",    "payload": payload  };  // Post the payload to Trello  try {    var response = UrlFetchApp.fetch('http://api.trello.com/1/cards/[id of my card]/idList', options);    Logger.log(response);  } catch (e) {    // Log any errors     Logger.log("ERROR:\n"+e.message);  }
```

Number 2:

```
function createOAthService_Trello() {  var consumerKey='*************************';  var consumerSecret = '********************************************************'  var service = OAuth1.createService("trello");  service.setAccessTokenUrl("https://trello.com/1/OAuthGetAccessToken");  service.setRequestTokenUrl("https://trello.com/1/OAuthGetRequestToken");  service.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?scope=read,write");  service.setPropertyStore(PropertiesService.getScriptProperties());  service.setCallbackFunction('authCallback_Trello');  service.setConsumerKey(consumerKey);  service.setConsumerSecret(consumerSecret);  return service;}function checkServiceAccess(){      var service = createOAthService_Trello();      var emailAddress ='*****@********.com';      if(service.hasAccess()){        return service;    }    else {      var authorizationUrl = service.authorize();      MailApp.sendEmail(emailAddress, 'Google Script App Needs Authorization (Trello)', 'Please visit the following URL and then re-run the script: ' + authorizationUrl);      Logger.log('Please visit the following URL and then re-run the script: ' + authorizationUrl);  }}function moveCard(){      var service = checkServiceAccess();      var url = 'http://api.trello.com/1/cards/[myCardId]/idList?value=[newListId]&token=[myToken]&cards=open&lists=open'      var options = {"method" : "put"};      var raw= service.fetch(url, options);      Logger.log(raw);}
```

This two pieces of code doesn't crash. But they don't move any card, and only return a Log with the ID of the list where they are placed.  
I have checked a thousand of times for the id's to be correct, so that can't be the problem. It doesn't seem to be a problem with the PUT request, because I can Update descriptions, titles,... But with the DELETE request,it fires a "Unexpected exception". Maybe they are related.

Also, I have tried to insert this on my code:

```
<html><script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script><script type="text/javascript" src="https://trello.com/1/client.js?key=*****************************"></script></html>//eval(UrlFetchApp.fetch('https://trello.com/1/client.js?key=************************').getContentText());var success = function(successMsg) {  asyncOutput(successMsg);};var error = function(errorMsg) {  asyncOutput(errorMsg);};Logger.log(Trello.get('/member/me/boards', success, error));
```

But it crash because it can't find the Trello global variable. I'm really desperate, any help will be apreciated . Thank you for your time! :)


Answers:
author: Oscar Triscon
body: \> This two pieces of code doesn't crash. But they don't move any card, and only return a Log with the ID of the list where they are placed.

This means the request has been successful. Is the list returned not the correct one? The id returned should match the idList you passed in your request, confirming that the card was moved to that new list.

comments: author: Sheila Venade
body: No, it returns the id where the card is placed. It doesn't even move it.

Thanks for helping :)


author: Oscar Triscon
body: Are you sure the idList you're passing is the correct one? If it's not moving it, you may be passing the existing list instead of the new one.


author: Sheila Venade
body: The ListId where its placed ends with 98, I'm trying to move to someone ended on 96...

Also, I realized that putting a wrong id works in the same way...


author: Oscar Triscon
body: So, when you PUT the idList for a card, you get back the card object, something like this:

```
{ "id": "A_CARD_ID", "badges": {  "votes": 0,  "viewingMemberVoted": false,  "subscribed": false,  "fogbugz": "",  "checkItems": 0,  "checkItemsChecked": 0,  "comments": 0,  "attachments": 0,  "description": false,  "due": null,  "dueComplete": false }, "checkItemStates": [], "closed": false, "dateLastActivity": "2017-04-26T16:06:36.553Z", "desc": "", "descData": null, "due": null, "dueComplete": false, "email": null, "idBoard": "A_BOARD_ID", "idChecklists": [], "idLabels": [], "idList": "A_LIST_ID", "idMembers": [], "idShort": 2870, "idAttachmentCover": null, "manualCoverAttachment": false, "labels": [], "name": "X", "pos": 98303, "shortUrl": "https://trello.com/c/XXXXXXX", "url": "https://trello.com/c/XXXXXXXX/2870-x"}
```

Where A_CARD_ID, A_BOARD_ID and A_LIST_ID are id numbers.

Does the idList returned not match the "value" parameter your pass in?


author: Sheila Venade
body: No, actually when I do the PUT it returns something like this:

```
{"_value" :"XXXXXXid from the original ListXXXXXX"}
```


author: Oscar Triscon
body: You're probably correct, I was writing off memory.

So the request goes through, you get an idList back, but it's not the new list's id?

I'm having a hard time reproducing your problem, so I'll tell you what differs between your code and the way I do it, perhaps you can try:

1. I pass the key and token in the query string instead of the payload.

2. I use "<https://trello.com>" not "<http://trello.com>" (pretty sure you're getting a redirect there).

But if your request is going through, then I'm not sure how this would help. Perhaps check if you have permission to move cards on that board? You should get a 401 though if you didn't.

Sorry, I can't think of anything else.


author: Oscar Triscon
body: Update: I'm almost sure I found the problem.

Change your URL scheme from http:// to https:// and it'll work.

The Trello API treats POSTing and PUTing to http as GET.


author: Sheila Venade
body: Oh my god, you are right!

Thank you so much, I almost give it up \^-\^'

You rocks!


author: Oscar Triscon
body: Never give up! :-)


Tags: api