Get a custom field used to return "id" but it isn't anymore?

I am issuing a request in my C# code to asana to get a custom field. The custom field is PA which stands for Project Administrator. When the response is returned I was parsing out id like so:
private long GetPAId(string task)
{
long idOfPA = 0;
string response = GetResponseAndRetry(String.Format(“https://app.asana.com/api/1.0/tasks/{0}?opt_pretty”, task));
if (response != “”)
{
var myClass = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(response);
foreach (CustomFieldCF cF in myClass.data.custom_fields)
{
if (cF.name == “PA”)
{
idOfPA = (long)cF.id;
return idOfPA;
}
}
}
return 0;
}

This was working great but now id is not returned anymore in the response so my code is exceptioning.  Did something change in the API?  I have a response I captured from last September compared with the response I am getting today..

  "id" : 1126645169471189,	 
  "gid" : "1126645169471189",
  "enabled" : true,	 	 
  "name" : "PA",	 	 
  "resource_subtype" : "text",	 
  "resource_type" : "custom_field",
  "text_value" : "Harry Potter",
  "type" : "text"	 	 

  "gid" : "1126645169471189",
  "enabled" : true,
  "name" : "PA",
  "resource_subtype" : "text",
  "resource_type" : "custom_field",
  "text_value" : "Harry Potter",
  "type" : "text"

id has gone poof?

I apologize; my post seems to have gotten butchered. I was trying to say “so now my code is exceptioning” and the first block of json I posted is what I was getting a few months ago; the second block is what I’m getting today. Obviously the fix is to use gid instead of id, but why all of a sudden it disappeared? Thanks.

This is why (and you had 18 months’ warning :slight_smile: ):

18 months ago the API team announced that they were switching to string IDs (which are found in the gid field), and it took that long for the whole process to happen. During much of that time, objects contained both the old numeric id and the new string gid, but as of Joe’s post referenced above, they finally removed the numeric id field about a week ago.

Not sure if you’re doing this but note that you should really not cast the new gid field to an int. For now, gid's are always numeric, but that’s not guaranteed to be the case forever so I’d highly recommend future-proofing your code by leaving and acting on gid as a string.

Thank you, I feel so much better, though a bit like a stupid a$$.
So perhaps I got this warning and ignored it? By what means are these warnings delivered?

Oh, and thank you also…I will remove the cast and work with it as a string!

1 Like

I’m actually not sure what means they used. I frequent the forum here so that’s how I kept up on it all; that’d be my recommendation going forward - check in here periodically on the Developers & API section.

For this particular deprecation, we announced the change on this forum, sent out emails to all developers on our mailing list, and ran an in-product announcement bar for about two weeks. To get the most current news and notifications, you can subscribe to the platform news category here on the forums, which is the first place we post new information.

2 Likes

Thank you, but can you tell me how to subscribe? I went to platform news and don’t see how one would do that. Thanks.

@MMOCK, I think what you want is to click the bell icon in the upper right and select “Watching”. That way, I believe you’ll get an email notification whenever a new post is made in that forum section.

1 Like