Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse response after creating card using Trello API

I'm playing around with the Trello API and I'm slowly getting the hang of it. I'm stuck on one piece where I manage to create a new card inside a speicifc list, but I'd like to parse the response I get from the "createCard" call e.g. to get the ID of the new card.

Here is my Trello create card post:

Trello.post("cards", { name: "Card Created from MVC", desc: "This is the description of the card.", idList: "??????????" }).done(onCardCreated());

I've omitted the real idList value for secutiry reasons.

I can see the card instantly on my Trello board. The response I get from this call starts like this:

jQuery1510518084118841216_1327764237952({"id":"????","name":"Card Created from MVC","desc":........)

I was expecting to see the JSON returned liked this:

{"id":"????","name":"Card Created from MVC","desc":....}

But in this case, the JSON is wrapped around in this jQuery1510518084118841216_1327764237952 thing.

Can some tell me what the jQuery thing is for, and how do I get to the JSON data inside of it?

like image 750
Jason Evans Avatar asked Nov 20 '25 04:11

Jason Evans


1 Answers

Because the request is going to another domain (i.e. api.trello.com), the client-side library is using JSONP.

The library is using jQuery's AJAX calls (with the jsonp dataType), which is why the JSONP callback has a "jQuery" name.

Although the actual response you see includes the JSONP callback, the response from the library that is given to the success callback should just include the JSON.

I would expect that something like this should work:

Trello 
.post("cards", { name: "Foo", desc: "Bar", idList:"..."}) 
.done(function(card) { alert(card.id) })
like image 167
Daniel LeCheminant Avatar answered Nov 21 '25 18:11

Daniel LeCheminant