Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Country API

Allows you to retrieve the list of countries from Magento.

Module: Mage_Directory

Resource: directory_country

Aliases:

  • country

Method:

  • directory_country.list (SOAP V1)
  • directoryCountryList (SOAP V2)

Retrieve the list of countries from Magento.

Aliases:

  • country.list
Arguments:
TypeNameDescription
stringsessionIdSession ID
Returns:
TypeNameDescription
arraycountriesAn array of directoryCountryEntity

The directoryCountryEntity content is as follows:

TypeNameDescription
stringcountry_idID of the retrieved country
stringiso2_codeISO 2-alpha code
stringiso3_codeISO 3-alpha code
stringnameName of the retrieved country

Examples

Request Example SOAP V1
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$countries = $proxy->call($sessionId, 'country.list');
var_dump($countries); // Countries list.
Request Example SOAP V2
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary

$result = $proxy->directoryCountryList($sessionId);
var_dump($result);
Request Example SOAP V2 (WS-I Compliance Mode)
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); 

$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey')); 
 
$result = $proxy->directoryCountryList((object)array('sessionId' => $sessionId->result));   
var_dump($result->result);
Response Example SOAP V1
array
  0 =>
    array
      'country_id' => string 'AD' (length=2)
      'iso2_code' => string 'AD' (length=2)
      'iso3_code' => string 'AND' (length=3)
      'name' => string 'Andorra' (length=7)
  1 =>
    array
      'country_id' => string 'AE' (length=2)
      'iso2_code' => string 'AE' (length=2)
      'iso3_code' => string 'ARE' (length=3)
      'name' => string 'United Arab Emirates' (length=20)
  2 =>
    array
      'country_id' => string 'AF' (length=2)
      'iso2_code' => string 'AF' (length=2)
      'iso3_code' => string 'AFG' (length=3)
      'name' => string 'Afghanistan' (length=11)