> ## Documentation Index
> Fetch the complete documentation index at: https://docs.countrystatecity.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Convert ISO Code

> Translate a country code between ISO 3166-1 alpha-2, alpha-3, and numeric formats

Convert a country code between the three ISO 3166-1 formats in a single call:

* alpha-2 ↔ alpha-3 (e.g. `US` ↔ `USA`)
* alpha-2 ↔ numeric (e.g. `US` ↔ `840`)
* alpha-3 ↔ numeric (e.g. `USA` ↔ `840`)

Useful when an upstream system gives you one format and a downstream service expects another.

<Note>**Availability:** Starter plan and above. Returns `403` on Community plan.</Note>

<Info>
  **Cache reuse:** Conversions share the same cache slot as [`/v1/iso/country`](/api/endpoints/lookup-country-by-iso). A previous `?iso2=US` lookup serves any `?from=iso2&value=US&to=...` conversion without a fresh database hit. The target column is extracted after the cache read, so different `to` values reuse the same slot.

  Numeric inputs `4` and `004` resolve to the same cache slot.
</Info>

<RequestExample>
  ```bash cURL (alpha-2 → alpha-3) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/iso/country/convert?from=iso2&to=iso3&value=US' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```bash cURL (alpha-3 → numeric) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/iso/country/convert?from=iso3&to=numeric&value=IND' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```bash cURL (numeric → alpha-2) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/iso/country/convert?from=numeric&to=iso2&value=840' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({ from: 'iso2', to: 'iso3', value: 'DE' });
  const response = await fetch(
    `https://api.countrystatecity.in/v1/iso/country/convert?${params}`,
    { headers: { 'X-CSCAPI-KEY': 'YOUR_API_KEY' } }
  );

  const { result } = await response.json();
  console.log(result); // "DEU"
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
    'https://api.countrystatecity.in/v1/iso/country/convert',
    params={'from': 'iso2', 'to': 'numeric', 'value': 'JP'},
    headers={'X-CSCAPI-KEY': 'YOUR_API_KEY'}
  )

  print(response.json()['result'])  # "392"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - Success (alpha-2 → alpha-3) theme={null}
  {
    "from": "iso2",
    "to": "iso3",
    "input": "US",
    "result": "USA"
  }
  ```

  ```json 200 - Success (alpha-3 → numeric) theme={null}
  {
    "from": "iso3",
    "to": "numeric",
    "input": "IND",
    "result": "356"
  }
  ```

  ```json 400 - Same from/to theme={null}
  {
    "status": "error",
    "message": "Invalid query parameters: from and to must be different"
  }
  ```

  ```json 400 - Value doesn't match from theme={null}
  {
    "status": "error",
    "message": "Invalid query parameters: value does not match the format required by from"
  }
  ```

  ```json 400 - Invalid format name theme={null}
  {
    "status": "error",
    "message": "Invalid query parameters: from: must be one of: iso2, iso3, numeric"
  }
  ```

  ```json 403 - Feature Restricted theme={null}
  {
    "status": "error",
    "message": "This feature is not available on your current plan.",
    "details": {
      "feature": "isoLookup",
      "currentTier": "community",
      "requiredTier": "starter",
      "upgradeUrl": "https://app.countrystatecity.in/pricing"
    }
  }
  ```

  ```json 404 - Source code unknown theme={null}
  {
    "status": "error",
    "message": "Country not found for the given code"
  }
  ```

  ```json 404 - Target column null theme={null}
  {
    "status": "error",
    "message": "No iso3 code available for this country"
  }
  ```
</ResponseExample>

## Related Endpoints

* [Lookup Country by ISO Code](/api/endpoints/lookup-country-by-iso) — return the full country record instead of just the converted code
* [Lookup State by ISO Code](/api/endpoints/lookup-state-by-iso) — ISO 3166-2 subdivision lookup


## OpenAPI

````yaml GET /iso/country/convert
openapi: 3.0.3
info:
  title: Country State City API
  description: >-
    Geographic data API providing countries, states, cities, timezones,
    currencies, and phone dial codes with tiered access levels.


    ## Authentication

    All endpoints require an API key passed via the `X-CSCAPI-KEY` header. Get
    your free key at [app.countrystatecity.in](https://app.countrystatecity.in).


    ## Pricing & Limits

    The fields returned, endpoints available, and request quotas depend on your
    plan. See current tiers and limits at:


    **[countrystatecity.in/pricing](https://countrystatecity.in/pricing)**


    ## Data Access Levels

    Each plan includes a data access level that controls which fields are
    returned:


    - **Basic** — Core fields: id, name, iso2, iso3, phonecode, capital,
    currency, coordinates, region, timezones, emoji

    - **Coordinates** — Basic + extended metadata (population, tld, nationality,
    currency details, postal codes, etc.)

    - **Full** — All fields including translations (18+ languages) and
    wikiDataId


    Fields restricted to higher tiers are marked in each schema below.


    ## Feature Gating

    Some endpoints require a minimum tier. Restricted endpoints return `403`
    with an `upgradeUrl` when accessed on a lower plan. Check the [pricing
    page](https://countrystatecity.in/pricing) for current feature availability.


    ## Rate Limiting

    Requests exceeding your daily or monthly quota receive a `429` response with
    your current limit, period, tier, and an upgrade URL.


    ## Caching

    Cacheable geographic responses include `Cache-Control`, `ETag`, and
    `X-Cache` (HIT/MISS) headers; send `If-None-Match` on them to receive `304
    Not Modified`. Phone number parsing is never cached (`Cache-Control:
    no-store`, no `ETag`); see each endpoint for exceptions.


    ## Usage Headers

    All `/v1/*` responses include usage and plan headers:

    - `X-CSC-Plan` — your current tier

    - `X-CSC-Daily-Used` / `X-CSC-Daily-Limit` — today's usage vs limit

    - `X-CSC-Monthly-Used` / `X-CSC-Monthly-Limit` — this month's usage vs limit


    Use these to monitor consumption without a separate API call.
  contact:
    name: Darshan Gada (dr5hn)
    email: gadadarshan@gmail.com
    url: https://countrystatecity.in
  license:
    name: Creative Commons Attribution 4.0
    url: https://creativecommons.org/licenses/by/4.0/
  version: 2.4.1
servers:
  - url: https://api.countrystatecity.in/v1
    description: Production API
security: []
tags:
  - name: Countries
    description: Country data — 250+ countries with metadata, coordinates, and translations
  - name: States
    description: State/province/region data — 5,000+ subdivisions
  - name: Cities
    description: City data — 150,000+ cities worldwide
  - name: Postcodes
    description: >-
      Postcode and ZIP code lookup and search. Informational data, not address
      verification.
  - name: Regions
    description: Geographic regions and subregions — continental groupings of countries
  - name: Timezones
    description: >-
      IANA timezone lookup by country, state, or city — includes UTC offset and
      DST status
  - name: Currencies
    description: ISO 4217 currency data — list all currencies or look up by country
  - name: Phone
    description: >-
      International dial codes — list, lookup by country, and E.164 phone number
      parsing
  - name: ISO
    description: >-
      ISO 3166 code lookup and conversion — country (alpha-2/3/numeric) and
      state (ISO 3166-2)
  - name: Search
    description: Typo-tolerant fuzzy search across cities, states, and countries
  - name: Changes
    description: >-
      Data change feed — track additions, removals, and updates to place records
      over time. **Professional and Business plans only.**
  - name: Meta
    description: Information about the dataset release currently served
paths:
  /iso/country/convert:
    get:
      tags:
        - ISO
      summary: Convert ISO country code
      description: >-
        Translates a country code between ISO 3166-1 formats: alpha-2 ↔ alpha-3
        ↔ numeric. All three conversion directions are supported.


        **Availability:** Starter+ plan required.
      operationId: convertIsoCountryCode
      parameters:
        - name: from
          in: query
          description: Source format
          required: true
          schema:
            type: string
            enum:
              - iso2
              - iso3
              - numeric
            example: iso2
        - name: to
          in: query
          description: Target format (must differ from `from`)
          required: true
          schema:
            type: string
            enum:
              - iso2
              - iso3
              - numeric
            example: iso3
        - name: value
          in: query
          description: The code to convert (e.g., `US` when `from=iso2`)
          required: true
          schema:
            type: string
            example: US
      responses:
        '200':
          description: Converted ISO code
          headers:
            Cache-Control:
              $ref: '#/components/headers/CacheControl'
            ETag:
              $ref: '#/components/headers/ETag'
            X-Cache:
              $ref: '#/components/headers/XCache'
            X-CSC-Plan:
              $ref: '#/components/headers/XCSCPlan'
            X-CSC-Daily-Used:
              $ref: '#/components/headers/XCSCDailyUsed'
            X-CSC-Daily-Limit:
              $ref: '#/components/headers/XCSCDailyLimit'
            X-CSC-Monthly-Used:
              $ref: '#/components/headers/XCSCMonthlyUsed'
            X-CSC-Monthly-Limit:
              $ref: '#/components/headers/XCSCMonthlyLimit'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IsoConvert'
        '400':
          description: Mismatched `from`/`to` formats, invalid value, or `from` equals `to`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/FeatureRestricted'
        '404':
          description: >-
            No country matches the value, or it has no code in the requested
            format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusError'
              example:
                status: error
                message: Country not found for the given code
        '429':
          $ref: '#/components/responses/RateLimited'
      security:
        - ApiKeyAuth: []
components:
  headers:
    CacheControl:
      description: Cache directive
      schema:
        type: string
        example: public, max-age=3600
    ETag:
      description: Entity tag for conditional requests (use with `If-None-Match`)
      schema:
        type: string
        example: '"a3f2b8c1d4e5f6a7b8c9d0e1f2a3b4c5"'
    XCache:
      description: Whether the response was served from cache
      schema:
        type: string
        enum:
          - HIT
          - MISS
        example: HIT
    XCSCPlan:
      description: Your current pricing tier
      schema:
        type: string
        enum:
          - community
          - starter
          - supporter
          - professional
          - business
          - legacy
          - custom
        example: supporter
    XCSCDailyUsed:
      description: Number of requests used today
      schema:
        type: integer
        example: 42
    XCSCDailyLimit:
      description: Your daily request limit (or 'unlimited' for custom plans)
      schema:
        type: string
        example: '1000'
    XCSCMonthlyUsed:
      description: Number of requests used this month
      schema:
        type: integer
        example: 850
    XCSCMonthlyLimit:
      description: Your monthly request limit (or 'unlimited' for custom plans)
      schema:
        type: string
        example: '30000'
  schemas:
    IsoConvert:
      type: object
      description: Result of an ISO 3166-1 code conversion.
      properties:
        from:
          type: string
          enum:
            - iso2
            - iso3
            - numeric
          description: Source format
          example: iso2
        to:
          type: string
          enum:
            - iso2
            - iso3
            - numeric
          description: Target format
          example: iso3
        input:
          type: string
          description: The input code, echoed back from the `value` query parameter
          example: US
        result:
          type: string
          description: The converted code. Numeric results are zero-padded to 3 digits.
          example: USA
      required:
        - from
        - to
        - input
        - result
    StatusError:
      type: object
      description: Error envelope used by the postcode and meta endpoints.
      properties:
        status:
          type: string
          example: error
        message:
          type: string
        details:
          type: object
          nullable: true
          properties:
            reason:
              type: string
              description: >-
                Machine-readable reason. Check this instead of parsing
                `message`.
          additionalProperties: true
      required:
        - status
        - message
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
      required:
        - error
    FeatureError:
      type: object
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          example: This feature is not available on your current plan.
        details:
          type: object
          properties:
            feature:
              type: string
              description: The feature flag that was denied
              example: bulkStates
            currentTier:
              type: string
              example: community
            requiredTier:
              type: string
              nullable: true
              description: >-
                Lowest plan that unlocks the feature; null when it cannot be
                determined
              example: starter
            upgradeUrl:
              type: string
              format: uri
              example: https://countrystatecity.in/pricing
          required:
            - feature
            - currentTier
            - requiredTier
            - upgradeUrl
      required:
        - status
        - message
        - details
    RateLimitError:
      type: object
      properties:
        error:
          type: string
          example: >-
            Daily usage limit exceeded. Please try again tomorrow or contact
            support for higher limits.
        limit:
          type: integer
          description: Your plan's limit for the exceeded period
          example: 100
        period:
          type: string
          enum:
            - daily
            - monthly
          example: daily
        tier:
          type: string
          description: Your current tier
          example: community
        upgradeUrl:
          type: string
          description: URL to upgrade your plan
          example: https://countrystatecity.in/pricing
      required:
        - error
  responses:
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Unauthorized. You shouldn't be here.
    FeatureRestricted:
      description: >-
        Feature not available on your current plan. Upgrade to access this
        endpoint. `details.feature` names the denied feature and
        `details.requiredTier` the lowest plan that includes it (the example is
        for `/states`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/FeatureError'
          example:
            status: error
            message: This feature is not available on your current plan.
            details:
              feature: bulkStates
              currentTier: community
              requiredTier: starter
              upgradeUrl: https://countrystatecity.in/pricing
    RateLimited:
      description: Daily or monthly usage limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
          example:
            error: >-
              Daily usage limit exceeded. Please try again tomorrow or contact
              support for higher limits.
            limit: 100
            period: daily
            tier: community
            upgradeUrl: https://countrystatecity.in/pricing
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: >-
        API key for authentication. Get your free key at
        [app.countrystatecity.in](https://app.countrystatecity.in).
      name: X-CSCAPI-KEY
      in: header

````

## Related topics

- [Lookup Country by ISO Code](/api/endpoints/lookup-country-by-iso.md)
- [Lookup State by ISO Code](/api/endpoints/lookup-state-by-iso.md)
- [Changelog](/changelog.md)
- [GraphQL API](/api/graphql.md)
- [TypeScript SDK](/api/sdks/typescript.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.