Asana Server Error without random phrase

subtasks
tasks

#1

Hi all,

I get this error when creating subtasks:

"{errors:[{message:\"Server Error\"}]}"

I’m pretty much sure that it’s my fault in some point of my code, but error doesen’t says me anything…

//Parameters of the JSON to make a POST
           jsonObjectBody.insert("assignee", QJsonValue::fromVariant("blablah@blablah.com"));
           jsonObjectBody.insert("notes", model.record(i).value("chrResponsable").toString());
           jsonObjectBody.insert("name", model.record(i).value("chrDescTarea").toString());
           jsonObjectBody.insert("workspace", QJsonValue::fromVariant("123456"));
           //Creating an object "data" to encapsulate previous fields           jsonObjectHeader.insert("data", jsonObjectBody);
           jsonDoc.setObject(jsonObjectHeader);

Whis worked fine creating main task. I’ve only changed endpoint’s URL:

From “/api/1.0/tasks” to “/api/1.0/tasks/845234493988631/subtasks” (Where 845234493988631 is the “gid” field that Asana gave me from main task.

I’ve performed same action via curl and it worked…

What can I check?

Regards,

Dani.


#2

If you are using gid, did you include the Http Header to activate this feature?

Bastien
Delegate tasks to a virtual assistant in Asana :computer:


#3

Hi Bastien,

I’m not sure what are you meaning… I’m using “gid” because my IDE (Qt) default type of “int” fields in JSON files is double and thats why I cannot use “id”…

My Http header is the same as the main task (So, error must be there), here is my header:

//We build HTTP header.
QString header = "Bearer " + access_token;
request.setRawHeader(QByteArray("Authorization"), QByteArray(header.toLatin1().data()));
//Set content type of the header
request.setHeader(request.ContentTypeHeader,"Content-Type: application/json");

What should I add to the header?

Regards!

Dani.


#4

oh ok, my bad, my message must have been weird!

That might help understand: Asana is moving to string IDs
gid is kind of a new thing.


#5

Hi Bastien…

Thanks for the aclaration! (I already knew about the change, but I didn’t read all about deprecations… my bad)

Anyway, it’s weird because i’m creating subtasks and their “gid” or “id” is on the URL (which is definitely a string…)

Should I set an:

            Asana-Enable: ¿¿gid??

on my headers?

I’m going to make some tests and I’ll give more details.

Regards,

Dani.


#6

I wish I could reply myself…

It didn’t work. I have notice something curious… I have 9 tasks on my database, with a “bool” field that marks if it’s task or subtask. My program reads the table and calls Asana in order to create those tasks.

My program creates all main tasks ok, but it fails all subtasks except by one, this is the debug:

1º- I create main task:

createMainTask: La URL del POST es:  "https://app.asana.com/api/1.0/tasks"
createMainTask: El JSON con los datos es:  QJsonDocument({"data":{"assignee":"blabla@blabla.com","name":"Aprobacion de pedido","notes":"Administracion","workspace":"1234567891011"}})
createMainTask: Ejecutando el POST...
createMainTask: La respuesta del POST es:  "{\"data\":{\"gid\":\"848632307137442\",\"id\":848632307137442,\"resource_type\":\"task\",\"created_at\":\"2018-10-03T06:14:51.483Z\",\"modified_at\":\"2018-10-03T06:14:51.483Z\",\"name\":\"Aprobacion de pedido\",\"resource_subtype\":\"default_task\",\"notes\":\"Administracion\",\"assignee\":{\"gid\":\"691704172010213\",\"id\":691704172010213,\"resource_type\":\"user\",\"name\":\"Daniel Izquierdo\"},\"completed\":false,\"assignee_status\":\"inbox\",\"completed_at\":null,\"due_on\":null,\"due_at\":null,\"projects\":[],\"start_on\":null,\"memberships\":[],\"tags\":[],\"workspace\":{\"gid\":\"1234567891011\",\"id\":1234567891011,\"resource_type\":\"workspace\",\"name\":\"CIC\"},\"num_hearts\":0,\"num_likes\":0,\"parent\":null,\"hearted\":false,\"hearts\":[],\"followers\":[{\"gid\":\"691704172010213\",\"id\":691704172010213,\"resource_type\":\"user\",\"name\":\"Daniel Izquierdo\"}],\"liked\":false,\"likes\":[]}}" 

2º - I get his GID and call subtasks endpoints:`

createSubTask: La URL del POST es:  "https://app.asana.com/api/1.0/tasks/848632307137442/subtasks"
createSubTask: El JSON con los datos es: QJsonDocument({"data":{"assignee":"blabla@blabla.com","name":"Revision y reserva de material para su producción, sobre todo pantallas","notes":"Almacen","workspace":"1234567891011"}})
createSubTask: Ejecutando el POST...
createSubTask: La respuesta del POST es:  "{errors:[{message:\"Server Error\"}]}" 

createSubTask: La URL del POST es:  "https://app.asana.com/api/1.0/tasks/848632307137442/subtasks"
createSubTask: El JSON con los datos es: QJsonDocument({"data":{"assignee":"blabla@blabla.com","name":"Revision de material restante por si hay que comprar // fabricar","notes":"Almacen","workspace":"1234567891011"}})
createSubTask: Ejecutando el POST...
createSubTask: La respuesta del POST es:  "{\"data\":{\"gid\":\"848631410715799\",\"id\":848631410715799,\"resource_type\":\"task\",\"created_at\":\"2018-10-03T06:14:53.916Z\",\"modified_at\":\"2018-10-03T06:14:53.916Z\",\"name\":\"Revision de material restante por si hay que comprar // fabricar\",\"resource_subtype\":\"default_task\",\"notes\":\"Almacen\",\"assignee\":{\"gid\":\"111111111111111\",\"id\":111111111111111,\"resource_type\":\"user\",\"name\":\"Daniel Izquierdo\"},\"completed\":false,\"assignee_status\":\"inbox\",\"completed_at\":null,\"due_on\":null,\"due_at\":null,\"projects\":[],\"start_on\":null,\"memberships\":[],\"tags\":[],\"workspace\":{\"gid\":\"1234567891011\",\"id\":1234567891011,\"resource_type\":\"workspace\",\"name\":\"CIC\"},\"num_hearts\":0,\"num_likes\":0,\"parent\":{\"gid\":\"848632307137442\",\"id\":848632307137442,\"resource_type\":\"task\",\"name\":\"Aprobacion de pedido\",\"resource_subtype\":\"default_task\"},\"hearted\":false,\"hearts\":[],\"followers\":[{\"gid\":\"111111111111111\",\"id\":111111111111111,\"resource_type\":\"user\",\"name\":\"Daniel Izquierdo\"}],\"liked\":false,\"likes\":[]}}" 

createSubTask: La URL del POST es:  "https://app.asana.com/api/1.0/tasks/848632307137442/subtasks"
createSubTask: El JSON con los datos es: QJsonDocument({"data":{"assignee":"blabla@blabla.com","name":"Creación de Chanel Asignación.","notes":"Produccion","workspace":"1234567891011"}})
createSubTask: Ejecutando el POST...
createSubTask: La respuesta del POST es:  "{errors:[{message:\"Server Error\"}]}" 

It only creates 2nd task, first one and last one gives me error… I dont know why… I’m going to debug step by step but it should create all task ok…

Regards,

Dani


#7

My advice would be to use id, make sure everything works, and then migrate to gid step by step. Can you try this?


#8

I notice that the first and third subtasks have accented characters, whereas the second subtask (the one that worked) does not. Maybe that’s an avenue to explore?


#9

Nope… or at least I haven’t researched how to do that…

My IDE, Qt, treats all JSON numbers as double, mostly because JSON specification does not clarify how implementations should handle numbers (https://doc.qt.io/qt-5/json.html), and since I get maintask’s ID from Asana’s response in JSON, I’m forced to use “gid” instead.

I could convert the double to int, but there I risk serious rounding errors and I’m not ready for that (I want to fight with gid a little bit more…)

I’ve figured another way to do this, creating the task with the parameter:

          "parent `{ id: 1234, name: 'Bug task' }`" 

But I think this way will be affecter by migration to strings id… I will tell you if it works!

Regards,

Dani


#10

And… once again… that was my fault.

In Spain we love accents, It seems Asana doesn’t…

I was sending my “notes” field with accents: “Actuación de protocolos”. I have to review my code collation in order to manage those accents…

API works fine wit gid in the URL or in the “parent” field anyway!

Regards.

Dani


#11

Hey @Daniel_Izquierdo, this sounds really frustrating. Sorry it took so much work to troubleshoot and that there isn’t yet an easy solution for you. I will bring this up with the API team.

Best,
Jeff


#12

Hi @Jeff_Schneider,

Thank you so much, yes, sometimes it can be frustrating, but when I realise whats happening it makes me very very happy ahahahaha.

As I said, It’s a “format” problem of my side… so please don’t waste your time on it. I think it could be ok to have an error control like “Hey, I dont like what you are sending to me”, but I dont know how much effort will it take…

Thank all you for your replies and your patience!

Dani.


#14

Hi Jeff, I’m following up on this because I ran into the same problem. I was unable to submit a new task due to an accented character being included; “Díaz”.

Oddly enough, while debugging this, I saw that the API will accept emoticons such as :pray:t3:.

Is this a limitation of the API that we should be working around or are you working to allow these characters through the API? Thanks.


#15

Hi Mat,

API allows accents. I had to set my header’s codification (charset=utf-8) in the right way to do that:

request.setHeader(request.ContentTypeHeader,"Content-Type: application/json; charset=utf-8");

Right know I’m able to submit “áóéíú” without any problem.

Regards!

Dani


#16

Dani, thank you for responding with your solution. I included the charset in the content-type header and it’s working now for me. Thanks a lot!