Access Scope Does Not Work in Shopify Remix App

In my embedded shopify app, I have an action route where im attempting to make graphql queries using admin.graphql. This works as expected with most of the queries I’ve used so far. However when using metaobjectDefinitionsCreate:

export const mutationCreateMetaobjectDefinition = `#graphql
    mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
        metaobjectDefinitionCreate(definition: $definition) {
            metaobjectDefinition {
                name
                type
                fieldDefinitions {
                    name
                    key
                }
            }
            userErrors {
                field
                message
                code
            }
        }
    }
`;
let res = await admin.graphql(
            mutationCreateMetaobjectDefinition,
            {
                variables: {
                    definition: {
                        name: 'Size Chart',
                        type: 'size-chart',
                        fieldDefinitions: [
                            {
                                description: 'Metaobject definition for product size charts',
                                key: 'chart',
                                name: 'Chart',
                                type: 'json',
                                validations: [
                                    {
                                        name: 'schema',
                                        value: JSON.stringify({
                                            "$schema": "http://json-schema.org/draft-07/schema#",
                                            "title": "SizeChartAsArrayOfArrays",
                                            "type": "array",
                                            "items": {
                                                "type": "array",
                                                "items": {
                                                    "type": "string"
                                                }
                                            }
                                        })
                                    }
                                ]
                            }
                        ]
                    }
                }
            }
        );

I receive the following error:

Error using admin graphQL GraphqlQueryError: Access denied for

metaobjectDefinitionCreate field. Required access: `write_metaobject_definitions` access scope.

My TOML has the required access scope (I have added both the read and write access scopes):

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_discounts,write_discounts,write_products,read_products,write_pixels,read_customer_events,read_orders,write_orders,read_metaobject_definitions,write_metaobject_definitions,read_metaobjects,write_metaobjects"

I have verified in the partner dashboard that the TOML access scopes are showing up:

I have uninstalled my app from the dev store and reinstalled it. I have also redeployed the app, and I ran the following graphql query:

let res = await admin.graphql(`#graphql 
    query Scopes {
        shop {
            name
        }
        app {
            availableAccessScopes {
            description
            handle
        }
        requestedAccessScopes {
            description
            handle
        }
    }
}`);

which confirms that the access scopes are there:

requestedAccessScopes: Array (13)
0 {description: "Read browsing behavior", handle: "read_customer_events"}
1 {description: "Read discounts", handle: "read_discounts"}
2 {description: "Read metaobject definitions", handle: "read_metaobject_definitions"}
3 {description: "Read metaobjects", handle: "read_metaobjects"}
4 {description: "Read orders, transactions, and fulfillments", handle: "read_orders"}
5 {description: "Read products, variants, and collections", handle: "read_products"}
6 {description: "Modify discounts", handle: "write_discounts"}
7 {description: "Write metaobject definitions", handle: "write_metaobject_definitions"}
8 {description: "Write metaobjects", handle: "write_metaobjects"}
9 {description: "Modify orders, transactions, and fulfillments", handle: "write_orders"}
10 {description: "Write access for pixels", handle: "write_pixels"}
11 {description: "Modify products, variants, and collections", handle: "write_products"}
12 {description: "Read access for pixels", handle: "read_pixels"}

I have no idea why this isnt working, I have gotten this to work in other applications. Is there a limit to the amount of access scopes any one app can have?

Any help would be greatly appreciated!

Hi Ricky,

Reinstalling the app should have allowed you to accept the write_metaobject_definitions scope, and it does look like the app has the access scopes from the query you’ve posted - so it’s very confusing why you’d still be seeing the “required access” error. As far as I know there’s no limit on the number of scopes an app can have. Have you tried installing the app with the updated toml onto a different dev store?

Hi Liam,

I haven’t tried installing on a different dev store, I’ll try that now and let you know what happens. Thanks!

Hi Liam,

I installed the app on a different dev store and it worked perfectly, I was prompted for access, and when I ran my process it created the definition as expected. I then tried on the troublesome dev store and I received the same error as above. This is quite weird, but at least I can just use the working dev store and continue working on the app. Thank you, wish I thought of this sooner!

Hey Ricky,

Glad to hear it’s working on a fresh store - although it should work on all stores. Maybe keep an eye on scopes/ auth with installing on other stores in case something is not configured correctly.

Will do! This app is already live on our production store. I’m just adding new features, deploying them to production will be the real test. When I get some time I will revisit this to track down whats actually happening. Thank you again!