Magento API v2 之webservice

http://yourserver.com/api/v2_soap /?wsdl v2是Java,.net等语言可调用,可模仿Customer

 

Basic steps:

1. Create Magento Extension (we are not going explain here how to do it)
2. Create Model for API method
3. Create and configure api.xml file
4. Create wsdl.xml file (with proper definitions)
5. Create wsi.xml file (with proper definitions) (OPTIONAL)

Creating Model for API v2

After properly configuring our config.xml it looks like this:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<?xml version= "1.0" ?>

 

<config>

    <modules>

       <Inchoo_Mapy>

          <version>1.0.1</version>

       </Inchoo_Mapy>

    </modules>

    < global >

       <models>

          <inchoo_mapy>

              < class >Inchoo_Mapy_Model</ class >

          </inchoo_mapy>

       </models>

    </ global >

</config>

Let’s navigate through Magento core files to see where Magento API models are in file-system:

Since we are going to use API v2 only, We will create our model like this:


Creating and configuring api.xml

The easiest way is to copy/paste one of Magento’s api.xml files in our etc folder and make changes there to suit our needs. Our final api.xml should look like this:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

<?xml version= "1.0" ?>

<config>

    <api>

      <resources>

      <!-- START GUSTOMER GROUP RESOURCES -->

        <mapy_customer_group>

             <model>inchoo_mapy/customer_group_api</model>

             <title>Inchoo Customer's Groups API</title>

             <acl>mapy_data</acl>

             <methods>

               <list translate= "title" module= "inchoo_mapy" >

                   <title>Retrieve customer groups</title>

                   <method>mapyItems</method>

               </list>

             </methods>

        </mapy_customer_group>

      <!--  END CUSTOMER GROUP RESOURCES -->

     </resources>

     <v2>

       <resources_function_prefix>

            <mapy_customer_group>mapy_customerGroup</mapy_customer_group>

            </resources_function_prefix>

     </v2>

     <acl>

        <resources>

            <mapy_data translate= "title" module= "inchoo_mapy" >

               <title>Mapy data</title>

               <sort_order>3</sort_order>

            </mapy_data>

        </resources>

     </acl>

   </api>

</config>

Here is logic that has to be implemented in api.xml file. Api.xml file basically connects API calls with php methods inside specific models. Also, the ACL resources are defined here for specific api call.

Creating wsdl.xml file

When working with wsdl.xml and wsi.xml later, if you are happy NetBeans user, I strongly suggest you to search on Google and download the XML Tools plug-in that can make life much easier …

There are few things that we have to fill-in when creating wsdl.xml.

  • Bindings
  • Port types
  • Messages
  • Types / Complex types

Also, it’s easier to copy one of Magento’s wsdl files, paste it in our etc folder and remove unnecessary things and add our own inside.

Here is NetBeans – XML Tools screen-shot how this look like:

This  image is showing logic and direction how should we fill-in wsdl.xml:

Let’s now look at real xml source:

After we finished with wsdl, let’s go to http://ourmagento/api/v2_soap/?wsdl=1 to see changes in global wsdl we made. (Don’t forget to clear cache first! ).

时间: 2024-09-18 16:04:05

Magento API v2 之webservice的相关文章

Magento API v1 之webservice

sales/etc/api.xml Java代码   <?xml version="1.0"?>   <config>       <api>           <resources>               <sales_order translate="title" module="sales">                   <model>sales/ord

api-谷歌地图API V2无法显示

问题描述 谷歌地图API V2无法显示 我在使用安卓谷歌API V2.0的过程中,发现谷歌地图一直无法显示,请问有人现在使用谷歌地图可以成功显示嘛?谷歌账号上的api申请过,但是一直没用,不知道是不是还有什么地方做的不对 解决方案 copy官方给的例子试试 你需要提供更详细的描述 解决方案二: 官方自己的就显示不出来,一片白 解决方案三: 官方自己的就显示不出来,一片白

Openstack组件实现原理 — Glance架构(V1/V2)

目录 目录 Glance 安装列表 Glance Image service Image service 的组件 Glance-Api Glance-Registry Glance-db Image StoreStore Backend Image Glance 架构 Glance Restful API V1 Glance Restful API V2 Glance 安装列表 Openstack组建部署 - Glance Install Glance Image service Image s

【译】如何应用最新版的谷歌表格 API

本文讲的是[译]如何应用最新版的谷歌表格 API, 引言 本文将演示如何使用最新的 Google 表格 API. Google 在 2016 I/O 大会上发布了第四版的表格 API(博客,视频),与之前版本相比,新版增加了大量功能.现在,你可以通过 API v4 完成 Google 表格移动版和桌面版的大部分操作. 文章下面会通过 Python 脚本,一步步将一个玩具公司关系型数据库里的客户订单数据逐条读出,并写到一个 Google 表格中.其他会涉及到的 API 还有:新建 Google 表

Google Maps API Web Services

原文:Google Maps API Web Services 摘自:https://developers.google.com/maps/documentation/webservices/   Google Maps API Web Services 本文将探讨 Google Maps API Web Services,这是一个为您的地图应用程序提供地理数据的 Google 服务的 HTTP 接口集合.本指南仅旨在介绍通用于所有不同服务的 Web 服务和托管信息.每个服务的单个文档位于以下位

接口-移动应用中 服务端API的设计

问题描述 移动应用中 服务端API的设计 php作为服务端 Android ,苹果 作为客户端,php 提供API接口的时候 应该怎么设计才能解决新旧版本 及 安卓 和 苹果版本不一致的问题,2. 怎么设计接口才能保证功能的可扩展性 和 灵活性 求教大家 能否给一个完整的例子 或者 说说思路也可以 解决方案 API中带一个版本信息http://www.xxx.com/api/v1.0http://www.xxx.com/api/v2.0 区分android和ios,可以在api中带一个os参数来

Web API 版本控制的几种方式

http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong-which-is.html 这篇文章写得很好,介绍了三种实现web api版本化的三种方式.我从评论里又收集到两种方式,所以一共是5种: 方式一:利用URL HTTP GET: https://haveibeenpwned.com/api/v2/breachedaccount/foo 方式二:利用用户自定义的request header HTTP GET: https://h

Solr查询语言 JSON Request API

一.背景与动机 JSON Request API是由noggit作者(同时也Solr Committer Leader)在Solr.5.3带来新特性,意在改善Solr原来复杂且又丑陋查询语法. 注:JSON Request API与Solr API v2并不是一回来,JSON Request API是一种新型Solr Query DSL.API v2新版本查询API,是基于Restful API实现的.当然JSON Request API显然是基于JSON实现的咯. 不过Request API还

谷歌地理开发博客宣布谷歌地图API将不再免费

Google的地理开发博客正式宣布,谷歌地图API(Google Maps API)将不再免费提供,而当用户调用谷歌地图的API超过一定限制以后,谷歌地图将会按照超出的次数来收取费用,而费用将是每一千次调用4-10美元左右. 对于开发商的影响 Google方面建议使用Google Maps API的开发商,可能需要评估一下如何调用谷歌地图的用法,从而确认他们的服务到底是否受到影响.而如果调用的次数超过了限制,那么就需要: 1.降低调用了Google Maps API的次数,会将其限制在每天的二万