Magento REST API-如何确定API基本URL? [英] Magento REST API - How to determine the API base URL?

查看:217
本文介绍了Magento REST API-如何确定API基本URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running Magento 2.2.5 and was having trouble working out what the URL was for making API requests. For example to GET a list of countries I had seen the following syntax used:

/rest/default/V1/directory/countries

在某些商店工作,但出现此错误:

which has worked on some stores, but I was getting this error:

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

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

I started playing around with the URL format and removed the "default" and used this instead:

/rest/V1/directory/countries

,然后请求成功.如何确定用于Magento REST API请求的基本URL?到目前为止,我找不到该文件.

and the requests were then successful. How does one determine what the base URL to use for Magento REST API requests? I haven't been able to find this documented so far.

推荐答案

Magento 2 Api的语法为

The syntax of Magento 2 Api is

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

此处store_code可以是Magento2实例的存储视图"中的任何一个.您可以在管理面板中获取商店代码.您可以使用store_code通过API获取特定于该商店视图的信息.默认情况下,Magento2安装附带1个网站,1个商店和1个商店视图(此商店视图的代码为" 默认 ",在您的情况下可能已更改,因此会出现错误).

Here store_code can be any one of the "store view" of your Magento2 instance. You can get the store code in admin panel. You can use store_code to get information specific to that Store View via API. By default Magento2 installation comes with 1 website, 1 store & 1 store view (this store-view has code "default", in your case this might have changed hence you get the error).

借助图像可以了解体系结构 参考图片 参考: https://docs.magento.com/m2 /ce/user_guide/stores/websites-stores-views.html

The architecture can be understand with the help of image Reference Image Ref: https://docs.magento.com/m2/ce/user_guide/stores/websites-stores-views.html

  • 当您指定store_code时,它将检查该特定商店视图的信息.如果在数据库中找不到指定的store_code,则Api返回无法处理指定的请求." 消息.

  • When you specify store_code it checks information for that particular Store-View. If the specified store_code is not found in the database, Api returns "Specified request cannot be processed." message.

当您未指定store_code时,它将首先查找默认的网站,然后查找此网站的默认商店.然后找到与此商店关联的默认商店视图.最后,它返回此默认Store-View的信息.默认存储和关联商店视图可以从管理面板更改. 参考图片

When you do not specify store_code it first finds default Website, then finds default Store for this Website & then finds default Store View Associated to this Store. And finally it returns information for this default Store-View. The association of default store & store-view can be changed from admin panel. Reference Image

因此,如果您需要存储特定信息,则API的URL应该在下面.如果需要所有商店的信息,可以将store_code设置为 all .

Hence the URL for API should be below in case you need store specific information. store_code can be set to all if you need information for all the stores.

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

这篇关于Magento REST API-如何确定API基本URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆