Getting exception while creating customer using api

Topic summary

A developer is encountering a 422 status code error when attempting to create a customer via Shopify’s REST API (version 2022-04).

Error Details:

  • The API returns: {"errors":{"addresses.province":["is not valid"]}}
  • This indicates the province field in the address object is being rejected

Request Structure:
The payload includes basic customer information (first_name, last_name, email, verified_email) and an addresses array with fields like address1, address2, city, and province.

Code Formatting Issue:
The posted code snippets appear corrupted or reversed in the original message, making it difficult to see the exact values being sent. The password confirmation fields suggest this might be part of a customer registration flow.

Status: The issue remains unresolved with no responses yet. The developer needs guidance on proper province formatting or valid province values for the API.

Summarized with AI on November 24. AI used: claude-sonnet-4-5-20250929.

Hi everyone, I am creating a customer using rest API(/admin/api/2022-04/customers.json) with the following payload.

{
    "customer": {
        "first_name": "john",
        "last_name": "doe",
        "email": "johndoe@example.com",
        "phone": null,
        "verified_email": true,
        "addresses": [{
            "address1": "",
            "address2": "",
            "city": "",
            "province": "City of London",
            "phone": "19876543210",
            "zip": "",
            "first_name": "john",
            "last_name": "doe",
            "country": "United Kingdom",
            "company": ""
        }],
        "password": "Suraut^23",
        "password_confirmation": "Suraut^23"
    }
}

and getting this exception from API

Error: StatusCodeError: 422 - {"errors":{"addresses.province":["is not valid"]}}