Carrier Service API - Invalid request

Topic summary

A developer is encountering a type error in their PHP application when processing Carrier Service API requests from Shopify. The issue stems from unexpected JSON structure where the address1 field in the origin object contains a nested array/object instead of a simple string value.

Key Technical Details:

  • The error occurs during JSON-to-object conversion: address1 parameter receives an array when a string is expected
  • The malformed JSON shows address1 containing a full address object with fields like first_name, phone, city, country_code, etc.
  • According to Shopify’s official Carrier Service API documentation, address1 should be a string, not an array

Current Status:

  • The developer questions why certain fields (like product_id) appear empty in the requests
  • The post was moved to the dedicated API forums for developer-level support
  • The issue appears to be an inconsistency between Shopify’s documented API format and actual request payloads being sent

Note: Portions of the provided text appear corrupted or reversed, making complete analysis difficult.

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

In my application build in PHP I have converter from JSON to object. But in logs I can see errors like:

Uncaught PHP Exception TypeError: "App\CarrierService\CarrierServiceAddress::__construct(): Argument #6 ($address1) must be of type ?string, array given, called

In my logs I can see JSON:

{
   "rate":{
      "origin":{
         "country":"GB",
         "postal_code":null,
         "province":null,
         "city":null,
         "name":"Shop location",
         "address1":{
            "first_name":null,
            "address1":null,
            "phone":null,
            "city":null,
            "zip":null,
            "province":null,
            "country":"United Kingdom",
            "last_name":null,
            "address2":null,
            "company":null,
            "latitude":null,
            "longitude":null,
            "name":"",
            "country_code":"GB",
            "province_code":null
         },
         "address2":null,
         "address3":null,
         "latitude":null,
         "longitude":null,
         "phone":null,
         "fax":null,
         "email":null,
         "address_type":null,
         "company_name":"myteststore-wp"
      },
      "destination":{
         "country":"DK",
         "postal_code":"8660",
         "province":null,
         "city":"rate test",
         "name":null,
         "address1":"rate test",
         "address2":null,
         "address3":null,
         "latitude":null,
         "longitude":null,
         "phone":null,
         "fax":null,
         "email":null,
         "address_type":null,
         "company_name":null
      },
      "items":[
         {
            "name":"",
            "sku":"XXXXXXXX",
            "quantity":1,
            "grams":100,
            "price":0,
            "vendor":null,
            "requires_shipping":true,
            "taxable":true,
            "fulfillment_service":"manual",
            "properties":null,
            "product_id":null,
            "variant_id":null
         }
      ],
      "currency":"GBP",
      "locale":"en"
   }
}

In docs I can see example for Shopify Request and I can see, that address is a string, not array. It looks like issue in Shopify API or docs. Why for example product_id is empty?

         "name":"Bob Norman",
         "address1":"24 Sussex Dr.",
         "address2":"",
         "address3":null,
         "phone":null,
         "fax":null,
         "email":null,
         "address_type":null,
         "company_name":null
      },
      "items":[
         {
            "name":"Short Sleeve T-Shirt",
            "sku":"",
            "quantity":1,
            "grams":1000,
            "price":1999,
            "vendor":"Jamie D's Emporium",
            "requires_shipping":true,
            "taxable":true,
            "fulfillment_service":"manual",
            "properties":null,
            "product_id":48447225880,
            "variant_id":258644705304
         }
      ],
      "currency":"USD",
      "locale":"en"
   }
}
1 Like

Hi there @sebastiandev !

I just wanted to let you know I have moved your query here to our dedicated API forums.

As we’re not able to provide developer-level support ourselves here we have provided this area for these questions.

These threads are monitored and responded to by our Partners and developers, so it’s the best place to direct your query.

All the best!

2 Likes