【问题标题】:Magento REST API - How to determine the API base URL?Magento REST API - 如何确定 API 基本 URL?
【发布时间】:2019-10-24 02:46:00
【问题描述】:

我正在运行 Magento 2.2.5,但无法确定用于发出 API 请求的 URL。例如,要获取国家/地区列表,我已经看到使用以下语法:

/rest/default/V1/directory/countries

这在一些商店有效,但我收到了这个错误:

{
"message" : "Specified request cannot be processed.",
"trace" : null
}

我开始使用 URL 格式并删除了“默认”并改用它:

/rest/V1/directory/countries

然后请求就成功了。如何确定用于 Magento REST API 请求的基本 URL 是什么?到目前为止,我还没有找到这个文档。

【问题讨论】:

  • 这个!!!这就是正是我讨厌 Magento 的原因....

标签: magento magento2


【解决方案1】:

Magento 2 Api 的语法是

http://<:host:>/rest/<:store_code:>/<:api_path:>

这里的store_code 可以是您的 Magento2 实例的任何“商店视图”。您可以在管理面板中获取商店代码。您可以使用store_code 通过 API 获取特定于该商店视图的信息。默认情况下,Magento2 安装带有 1 个网站、1 个商店和 1 个商店视图(此商店视图的代码“default”,在您的情况下,这可能已经改变,因此您得到错误)。

架构可以借助图像来理解 Reference Image 参考:https://docs.magento.com/m2/ce/user_guide/stores/websites-stores-views.html

  • 当您指定store_code 时,它会检查该特定商店视图的信息。如果在数据库中没有找到指定的store_code,则Api返回“Specified request cannot be processed.”消息。

  • 当您不指定 store_code 时,它首先查找默认 Website,然后查找此网站的默认 Store,然后查找默认 Store View 与此商店关联。最后,它返回此默认存储视图的信息。可以从管理面板更改默认商店和商店视图的关联。 Reference Image

因此,如果您需要存储特定信息,API 的 URL 应如下所示。如果您需要所有商店的信息,store_code 可以设置为 all

http://<:host:>/rest/<:store_code:>/<:api_path:>

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多