How to fetch a task's "GitHub" field via the Asana API?

We use the Asana GitHub integration. This adds a “GitHub” field to each task, which can be set to the URL of a GitHub PR. (This is some kind of custom field that becomes available when I add the GitHub integration to a project. I’m not creating this field myself.)

How can I fetch the value of this field via the Asana API?

When I fetch the task via the API, I can’t see my PR URL anywhere in the response. For example, the “custom_fields” response field is an empty list.

Hi Kannan and welcome to the forum,

It’s not stored as a custom field (hence why you’re not seeing it there). It’s actually stored as an attachment (that’s just part of the way the Asana App Component architecture works). If you get the attachments on that task, you’ll see it, like this:

"data": [
    {
      "gid": "1203501329637667",
      "name": "#1 My Test PR",
      "resource_type": "attachment",
      "resource_subtype": "external",
      "connected_to_app": false
    }
  ]
2 Likes

Oh, nice! One more question – how can I confirm whether the attachment represents the “GitHub” field?

This is what I get when I fetch the attachment details:

{
  gid: '1203324273776472',
  created_at: '2022-11-09T00:32:27.383Z',
  download_url: null,
  host: 'external',
  name: '#11 Test',
  parent: {
    gid: '1203324273776468',
    name: 'k4 real',
    resource_type: 'task',
    resource_subtype: 'default_task'
  },
  permanent_url: 'https://app.asana.com/app/asana/-/get_asset?asset_id=1203324273776472',
  resource_type: 'attachment',
  resource_subtype: 'external',
  view_url: 'https://github.com/xxxx/yyyy/pull/11',
  connected_to_app: false
}

I can do a regex match on “view_url”, but that could have false positives in strange situations. Is there are more reliable way to tell?

No, I don’t think so. That attachment is really intended to be for internal use by the integration, not directly by an Asana user; you’re supposed to pretend it’s not there. :laughing: