0

I'm building a script that will notify a hipchat room about changes on tasks, comments, etc. in Asana.

I'm facing 3 simple problems but I'm stuck and was thinking maybe some of you could help me.

Problem #1: The problem i'm facing is that when someone (a user) get's "mentioned or hyperlinked" in a comment I get a random URL with numbers I can't much to user ID or anything. Maybe there is a logic I'm not seeing?

Same with hyperlinks for tasks and projects? Could you please advice what's the first number of the URL and the second one?

See below the response i'm getting when I get a story from Asana API [8] => Array ( [id] => 10976152589055 [created_at] => 2014-03-15T04:51:40.831Z [created_by] => Array ( [id] => 203288254516 [name] => Juan Martitegui )

                [type] => comment
                [text] => https://app.asana.com/0/639593560275/639593560275Â testing.

https://app.asana.com/0/241863293563/241863293563Â testing. https://app.asana.com/0/591143197873/591143197873Â testing.

[*] this last 3 URLs are mentions of a USER!

I need that so I in the notification I can actually mention the Users name.


Problem #2: To see which tasks have been updated .. I check the "modification" timestamp and then post all the stories of those tasks to the room in a neat, clear way. The problem is if I create a new task... without modifying it.. that doesn't create a "story" so my "notification" will be empty. Any work around?

Problem #3: Is there a way to search all the modified tasks in a workspace in the last day (regardless of a user) or even better all the modified stories of a workspace in the last day for example?

Let me know please!

Thanks so much.

The code I'm using right now look like this:


    $api = 'xxxxxxx';
    $api_url = 'https://app.asana.com/api/1.0';
    $url = 'https://app.asana.com/api/1.0/tasks/10976287567521/stories';

    // workspaces/203178557772/tasks?assignee=203288254516&completed_since=now

    // tasks/203288254519/stories

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Don't print the result
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_FAILONERROR, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Don't verify SSL connection
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); //         ""           ""
    curl_setopt($curl, CURLOPT_USERPWD, $api);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
    // $data = array(
    //     "data" => array(
    //         "workspace" => "203178557772",
    //         "name" => "Task Name",
    //         "notes" => "notes",
    //         "assignee" => "203288254516"
    //     )
    // );
    // $data = json_encode($data);
    // curl_setopt($curl, CURLOPT_POST, true);
    // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);        
    $html = curl_exec($curl);
    curl_close($curl);
    $html = json_decode($html, true);

    echo $url . '

'; print_r($html);

1 Answers1

1

This is (as you keenly observed) really three separate questions (or, well, two), so I'll answer the one that's in the title :-)

So, the answer to your first question is this is a quirk of how we represent links to users in Asana - we actually link to that person's "Assigned to Me" project. Unfortunately, there isn't yet a convenient way to map these in the API, but this is actually something we're working on, we just aren't ready to publish the solution yet, so you'll have to wait on that one I'm afraid.

Additionally, you may want to check out the modified_since in the API docs (you'll find it in the "Querying for tasks" section).

agnoster
  • 3,744
  • 2
  • 21
  • 29
  • 1
    Thanks so much! Sorry I'm new to programming and this is my first stackoverflow question. Next time I'll do them separate. Thanks again for your answer. – JuanMartitegui Mar 15 '14 at 23:26
  • @agnoster Any updates on the person's mentions in comments? Is there anyway to at least get the User's name from the user/domain id? I don't necessarily need the link, I just want a human-readable representation of the users name – mkral Sep 30 '14 at 21:42
  • We are working on a hypertext version of the API which would allow you to get the name for a link. It's not ready for production use, but you can try using `opt_fields` to request `html_text` or `html_notes` instead of `text`/`notes`. We may embed additional information in the link (like `Tom Bizarro`), but that hasn't yet been implemented or even fully fleshed-out. – agnoster Oct 01 '14 at 16:38