Requesting optional access scopes

I’m trying to use AppBridge’s shopify.scopes.request method to obtain new scopes. But every time I see an error in console logs:

RequestError: Error occurred when attempting to request access scopes: RequestGrantUserError: The app does not have scopes declared on Shopify.

Shopify CLI is the latest. Config is:

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_products,read_metaobject_definitions,read_customer_events,write_metaobject_definitions,write_metaobjects,write_pixels"
optional_scopes = [
  "unauthenticated_read_product_listings",
  "unauthenticated_read_metaobjects",
  "unauthenticated_read_selling_plans",
  "read_discounts"
]
use_legacy_install_flow = true

I also saw this post App Bridge Scopes API Error After removing use_legacy_install_flow flag and tried all the suggested solutions, but I had no luck.

Any ideas how to fix this error?

As you are using legacy install flow, I don’t believe you can use the scopes declared in TOML or app bridge request scopes.
You’d need to migrate to managed installs for this.