How to set a custom country field using the API
Any field (including custom fields) that accepts an option value will take either its machine name or it's id. The machine names for countries are their ISO codes, e.g. the code for 'United States' is 'US'. So you could do:

civicrm_api3('Contact', 'create', array(
  'custom_77' =&gt; 'US',
));


which is equivalent to

civicrm_api3('Contact', 'create', array(
  'custom_77' =&gt; 1228,
));


The label "Uganda" will not work, as it's not considered reliable given translations and word-replacements.

To find the ISO code for a country, use the api explorer. Api Country get with name = Uganda reveals "iso_code": "UG"