Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
88 stars 9 forks source link

Resource fetching is using wrong API version #409

Open awd opened 2 months ago

awd commented 2 months ago

Describe the bug

When using Resource Fetching, the API version is incorrectly returning 2023-10 instead of latest as specified.

To Reproduce

Steps to reproduce the behaviour:

  1. Make app bridge resource fetch to Shopify direct api access: fetch(‘shopify:admin/api/graphql.json’)
  2. Open chrome inspector > Network tab
  3. View request headers X-Shopify-Api-Version: 2023-10

Expected behaviour

fetch(‘shopify:admin/api/graphql.json’) should use the latest stable api version (currently: 2024-07)

Contextual information

Workaround can be used to hard-code the api version into the path: fetch(‘shopify:admin/api/2024-07/graphql.json’)

Packages and versions

App Bridge SDK loading from CDN: https://cdn.shopify.com/shopifycloud/app-bridge.js

Additional context

API versions are now defined in the app TOML, app bridge should either respect that API version or when version is omitted from the fetch path - actual latest should be used.

billfienberg commented 2 months ago

@awd, thank you for this detailed bug report. A fix has been deployed. Please let us know if you continue experiencing the same issue.

awd commented 2 months ago

Hey @billfienberg

Thanks for the quick turn around on this one! Looks like it's back to using the latest version as hoped.

Is this now scoped to the app toml file? I can open a feature request if not, as hard-coding api versions in all the direct access network calls is a pain to maintain, and the default of latest is a moving target - this could break apps in the future as inputs / mutations / queries change.

Would love for there to be:

[access.admin]
api_version = "2024-07"
direct_api_mode = "online"
embedded_app_direct_api_access = true
BusyginArtem commented 2 months ago

Is there any chance to set some specific version? I'd like to use the 2023-10 version not the latest one.

vadym-perenesenko-moc commented 2 months ago

@BusyginArtem Then you just use a url like this fetch('shopify:admin/api/2023-10/graphql.json')

Screenshot 2024-08-06 at 14 17 17 Screenshot 2024-08-06 at 14 17 23
billfienberg commented 2 months ago

Is this now scoped to the app toml file?

Good news: We've created a ticket to implement that. Bad news: My prior PR needs to be reverted because it created a deviation from how Shopify versioned APIs are supposed to behave.

If your request doesn't include a version, then the API also defaults to the oldest supported stable version. - https://shopify.dev/docs/api/usage/versioning

Takeaway: Embedded apps using Direct API that want to use the latest stable API version will have to use the workaround until we implement the app toml scoping.

Workaround: Add the desired API version in the request URL: