Re: Cannot add localizationExtensions

Cannot add localizationExtensions

mckingho
Shopify Partner
3 0 0

api version: 2024-10

request url: https://xxx.myshopify.com/admin/api/2024-10/graphql.json

query:

mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
      localizationExtensions(first:1) {
        edges {
          node {
            key
            value
          }
        }
      }
    }
  }
}
graphql variables:
{
    "input": {
        "email": "test@example.com",
        "lineItems": {
            "variantId": "gid://shopify/ProductVariant/xxxxxx",
            "quantity": 1
        },
        "localizationExtensions": {
            "key": "TAX_CREDENTIAL_MX",
            "value": "test"
        }
    }
}
The result is
{
    "data": {
        "draftOrderCreate": {
            "draftOrder": {
                "id": "gid://shopify/DraftOrder/xxxxxxx",
                "localizationExtensions": {
                    "edges": []
                }
            }
        }
    },
    "extensions": {
        "cost": {
...
        }
    }
}
I follow this doc to test the api. But it does not set localizationExtensions.
What is the problem?
Replies 5 (5)

websensepro
Shopify Partner
2109 262 313

Hi @mckingho 

The issue likely lies in the format of the localizationExtensions input. In your query, localizationExtensions is being sent as a single object, but Shopify's API expects it to be a list (array) of objects. This discrepancy may be why the localizationExtensions are not being set in the draft order.

Correct Format

According to the Shopify documentation on adding locally required order data, localizationExtensions should be provided as an array of objects.

Here’s the corrected GraphQL query and variables:

Query:

mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
      localizationExtensions(first: 1) {
        edges {
          node {
            key
            value
          }
        }
      }
    }
  }
}

Variables:

{
  "input": {
    "email": "test@example.com",
    "lineItems": [
      {
        "variantId": "gid://shopify/ProductVariant/xxxxxx",
        "quantity": 1
      }
    ],
    "localizationExtensions": [
      {
        "key": "TAX_CREDENTIAL_MX",
        "value": "test"
      }
    ]
  }
}

Key Changes:

  1. localizationExtensions as an Array: The localizationExtensions field should be a list ([]) of key-value objects, not a single object.

  2. lineItems as an Array: Shopify requires lineItems to be an array of objects, even if there is only one line item.

Why the Fix Works

 

     Shopify GraphQL expects fields like localizationExtensions and lineItems to follow a specific structure. Using a single object where an array is required can result in the input being ignored, as in your case.

     After correcting the input format, the localizationExtensions data should be properly processed and reflected in the response.

Testing the Fix

Retry the query with the corrected format. If the issue persists, verify that:

      Your Shopify store has the relevant localization setup for the key you're adding (e.g., TAX_CREDENTIAL_MX).

      You have the necessary permissions for using this field in the API.

 

If my reply is helpful, kindly click like and mark it as an accepted solution.
If you are happy with my help, you can help me buy a COFFEE
Thanks!

Need a Shopify developer? Hire us at WebSensePro For Shopify Design Changes/Coding
For Free Tutorials Subscribe to our youtube
Get More Sales Using Big Bulk Discount APP
Create Your Shopify Store For Just 1$/Month
Get More Sales Using Big Bulk Discount APP
mckingho
Shopify Partner
3 0 0

Thanks for answering. I have updated both lineItems and localizationExtensions to array format. It still does not work. lineItems is set but localizationExtensions is not set.

 

Here's my updated request.

query

 

mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
      lineItems(first: 10) {
        edges {
            node {
                id
            }
        }
      }
      localizationExtensions(first:1) {
        edges {
          node {
            key
            value
          }
        }
      }
    }
  }
}

 

 

graphql variables

 

{
    "input": {
        "email": "test@example.com",
        "lineItems": [{
            "variantId": "gid://shopify/ProductVariant/xxxxx",
            "quantity": 1
        }],
        "localizationExtensions": [{
            "key": "TAX_CREDENTIAL_MX",
            "value": "test"
        }]
    }
}

 

 

response

 

{
    "data": {
        "draftOrderCreate": {
            "draftOrder": {
                "id": "gid://shopify/DraftOrder/xxxx",
                "lineItems": {
                    "edges": [
                        {
                            "node": {
                                "id": "gid://shopify/DraftOrderLineItem/xxxx"
                            }
                        }
                    ]
                },
                "localizationExtensions": {
                    "edges": []
                }
            }
        }
    },
    "extensions": {
        "cost": {
...
        }
    }
}

 

websensepro
Shopify Partner
2109 262 313

The issue might be related to how the localizationExtensions feature is implemented or configured in your Shopify store. Let’s troubleshoot and resolve this:

Potential Reasons and Fixes:

1. Localization Extensions Feature Not Enabled

  • The localizationExtensions field may not be enabled for your Shopify store or the market associated with the draft order.
  • Verify that your store has Markets configured properly, and ensure that the TAX_CREDENTIAL_MX key is a valid and enabled field for the market you're working with.

2. Key-Value Pair Validation

  • Ensure that the key (TAX_CREDENTIAL_MX) and value (test) are supported and valid for your store.
  • Double-check that the market associated with the order allows this specific key.

3. Missing Permissions

  • Confirm that the API token being used has the necessary permissions to modify and view localizationExtensions. These permissions might be linked to Shopify Markets and localization features.

4. API Behavior Limitation

  • Shopify may only apply localizationExtensions when specific conditions are met (e.g., the market's localization requirements or the draft order's billing/shipping addresses).
  • If the order does not meet these criteria, the localizationExtensions might not be set.

Suggested Debugging Steps:

  1. Check Market Configuration:

    • Go to Settings > Markets in your Shopify admin.
    • Ensure that the market associated with the draft order is properly configured and that TAX_CREDENTIAL_MX is listed as a supported localization extension.
  2. Test Another Key-Value Pair:

    • Try using a different key (e.g., TAX_CREDENTIAL_CA for Canada or another valid key for your store).
    • Example:
      {
          "key": "TAX_CREDENTIAL_CA",
          "value": "test"
      }
  3. Include Shipping/Billing Address:

    • Some localization extensions may require a valid shipping or billing address to work. Update your input to include:
      "shippingAddress": {
          "address1": "123 Main St",
          "city": "Mexico City",
          "country": "MX",
          "zip": "12345"
      }
  4. Contact Shopify Support:

    • If the issue persists, this could be a bug or limitation with the API. Contact Shopify Support or open a thread in the Shopify forums to confirm whether this feature is fully supported in your context.

Updated Request Example:

Here’s a refined example that incorporates potential fixes:

{
    "input": {
        "email": "test@example.com",
        "lineItems": [
            {
                "variantId": "gid://shopify/ProductVariant/xxxxx",
                "quantity": 1
            }
        ],
        "shippingAddress": {
            "address1": "123 Main St",
            "city": "Mexico City",
            "country": "MX",
            "zip": "12345"
        },
        "localizationExtensions": [
            {
                "key": "TAX_CREDENTIAL_MX",
                "value": "test"
            }
        ]
    }
}

Next Steps:

  1. Test the updated request.
  2. Check the Shopify admin to verify if the draft order has the localization extensions attached.
  3. If it still doesn’t work, consider reaching out to Shopify to clarify API behavior and ensure the feature is active for your store.
Need a Shopify developer? Hire us at WebSensePro For Shopify Design Changes/Coding
For Free Tutorials Subscribe to our youtube
Get More Sales Using Big Bulk Discount APP
Create Your Shopify Store For Just 1$/Month
Get More Sales Using Big Bulk Discount APP

mckingho
Shopify Partner
3 0 0

I tried draftOrderCreate and orderUpdate mutation with BR and MX data.

 

Data I use:

{
    "input": {
...
        "localizationExtensions": [{
            "key": "TAX_CREDENTIAL_BR",
            "value": "39053344705"
        }]
    }
}
{
    "input": {
...
        "localizationExtensions": [{
            "key": "TAX_CREDENTIAL_MX",
            "value": "HEGA820506M10"
        }]
    }
}

 

1. draftOrderCreate, both not set

{
    "data": {
        "draftOrderCreate": {
            "draftOrder": {
...
                "localizationExtensions": {
                    "edges": []
                }
            }
        }
    },
    "extensions": {
        "cost": {
...
        }
    }
}

 

2. updateOrder, TAX_CREDENTIAL_BR can be set correctly.

TAX_CREDENTIAL_MX is not set and returns invalid key error.

{
    "data": {
        "orderUpdate": {
            "order": {
...
            },
            "userErrors": [
                {
                    "message": "Localization extension: 'key' provided is invalid",
                    "field": [
                        "localizationExtensions",
                        "0",
                        "message"
                    ]
                }
            ]
        }
    },
    "extensions": {
        "cost": {
...
        }
    }
}

 

websensepro
Shopify Partner
2109 262 313

@mckingho 

It seems like you are trying to use draftOrderCreate and orderUpdate mutations in a GraphQL API to add localization extensions for Brazilian and Mexican tax credentials. Here's a breakdown of your issue and suggestions on how to resolve it.

Problem Summary:

  • You are able to successfully set TAX_CREDENTIAL_BR (Brazil) during the orderUpdate mutation.
  • However, when you attempt to set TAX_CREDENTIAL_MX (Mexico), you get an "invalid key" error.
  • Both keys seem to be used in draftOrderCreate, but neither is set in the result.

Potential Causes and Solutions:

  1. Invalid Key for Mexico:

    • The error message you received indicates that the key TAX_CREDENTIAL_MX is invalid. This suggests that either:
      • TAX_CREDENTIAL_MX is not a valid key in your system, or
      • The API doesn't recognize TAX_CREDENTIAL_MX for the localizationExtensions field.

    Solution:

    • Check the API documentation to see if TAX_CREDENTIAL_MX is a supported key. It's possible that the correct key for Mexico might be something else, like RFC_MX (for Registro Federal de Contribuyentes) or another valid identifier.
  2. Schema Mismatch:

    • The system might not have been configured to handle TAX_CREDENTIAL_MX in certain mutations (such as orderUpdate). Some systems might have specific validation for the available keys.

    Solution:

    • To troubleshoot, try a different key for Mexico. You might need to use an alternate key for tax credentials like RFC_MX or another supported key.
  3. Localization Extensions in draftOrderCreate:

    • You mentioned that localizationExtensions were not set in the result of draftOrderCreate, which indicates the API did not accept or save the localization data properly during the creation of the draft order.

    Solution:

    • Ensure the correct format and API behavior for draftOrderCreate. It’s possible that draftOrderCreate might require additional setup or validation to allow localization extensions to be added.
    • Test by adding localization extensions in a different format, or try using only one key (e.g., TAX_CREDENTIAL_BR) and see if the issue persists for draftOrderCreate.
  4. API Configuration and Permissions:

    • There could be an issue with how your API is configured to handle localization extensions for Mexico. Ensure that the API you're working with has the proper configuration to handle both BR and MX tax credentials, and that the system supports them.

Suggested Actions:

  1. Test with different localization keys: Try replacing TAX_CREDENTIAL_MX with a known valid key like RFC_MX (for Mexico), as it might be the correct key for tax credentials in Mexico.

  2. Check API documentation for localization keys to confirm if TAX_CREDENTIAL_MX is a valid key for localization extensions or if there is an alternate key like RFC_MX.

  3. Check for API updates or restrictions: Some APIs have limitations or updates that might restrict or validate specific keys. Ensure the system supports both BR and MX credentials properly.

  4. Validate during Draft Order Creation: If draftOrderCreate is not setting the localization extensions, check the API's handling of localization data at that stage. If needed, refer to the API’s official documentation for creating draft orders with custom localization extensions.

  5. Test with simple data: Test the system by setting only one localization key (e.g., TAX_CREDENTIAL_BR for Brazil) in both draftOrderCreate and orderUpdate to check if the issue is specific to the combination of keys.

Example GraphQL Request for Testing:

You can modify your request like this to test the new key:

{
    "input": {
        "localizationExtensions": [{
            "key": "RFC_MX",
            "value": "HEGA820506M10"
        }]
    }
}

Conclusion:

The core issue seems to be related to invalid key for Mexico (TAX_CREDENTIAL_MX). Double-check the API documentation to confirm the correct key, and consider using alternatives like RFC_MX for Mexico.

Need a Shopify developer? Hire us at WebSensePro For Shopify Design Changes/Coding
For Free Tutorials Subscribe to our youtube
Get More Sales Using Big Bulk Discount APP
Create Your Shopify Store For Just 1$/Month
Get More Sales Using Big Bulk Discount APP