Metaobject definition not found

When I try to upsert metaobject with metaobjectUpsert mutation for some shops I get this error:

[{"field" => ["metaobject"], "message" => "Metaobject definition not found"}]

The metaobject is defined in TOML:

[metaobjects.app.deal_list]
name = "Deal List"
access.storefront = "public_read"

[metaobjects.app.deal_list.fields.deals]
name = "Deals"
type = "json"
required = true

The shop has correct access scopes (write_metaobject_definitions, write_metaobjects). When I query the defitions they seem to be there:

{"metaobjectDefinitions" =>
  {"nodes" =>
    [
     {"type" => "app--2935586817--deal_block"},
     {"type" => "app--2935586817--deal_list"},
    ]
  }
}

The other metaobject (deal_block) does not have this issue and is upserting successfully.

This error seems to affect only a few percents of stores. Both metaobjects in question were added to TOML before the shops installed our app.

1 Like

Hello @dostu ,

This error “Metaobject definition not found” is happening because the type you are passing in the metaobjectUpsert mutation does not exactly match the actual metaobject definition type stored in that specific shop. Even though your TOML configuration is correct and the definition exists, Shopify does not use deal_list or app.deal_list internally, it generates a full type in this format: app--{APP_ID}--deal_list. That {APP_ID} is unique per app installation, so if you hardcode just deal_list or use a type from another environment (like dev vs production app), it will work for some shops and fail for others. That’s why only a few stores are affected.

The correct solution is to not hardcode the type at all. Instead, first query metaobjectDefinitions for the shop, find the definition where the name is “Deal List,” and store its definitionId. Then, in your metaobjectUpsert mutation, pass definitionId instead of type. Using definitionId ensures Shopify links the metaobject to the correct definition regardless of app ID differences, environment changes, or reinstall history. Additionally, if the metaobject was added later in TOML, make sure you run shopify app deploy (or --force) so definitions sync properly for all installs. In short, the issue is caused by a type mismatch, and the exact solution is to fetch and use the definitionId dynamically instead of relying on a hardcoded type.

@dostu I’ve DMed you to follow-up.