Make a basic SOAP call in Magento

Magento has a core API that allows developersto access customer, product, and transaction data via the simpleobject access protocol (SOAP).

Magento's SOAP API makes the platform especially easy tointegrate with third-party systems, including accounting systems,enterprise resource planning (ERP) solutions, or any number ofother systems.

In this article, I will demonstrate how to set up a Magento webservices user and get some basic product information from Magentousing SOAP.

Create a Magento Web Service User

Magento requires that you create specific web service users toaccess the SOAP API. To create these users, navigate to the Magentoadministration panel. Select System > Web Services> Roles and create a new role. For this example, Icall the role "SOAP-Full."

To use the SOAP API, begin by creating a web services user role in the Magento administrative panel.

To use the SOAP API, beginby creating a web services user role in the Magento administrativepanel.

Under the "Role Resources" tab at the left side of the page,you'll find a list of role privileges that you can toggle on or offfor a given role. You may create one role that has access to everyaspect of the Magento site or you can create several less powerfulroles that each has access to some specific section of the site'sdata.

Magento allows roles to have very specific privileges.

Magento allows roles tohave very specific privileges.

After saving the new role, navigate to System >Web Services > Users and add a new user.

The API key is the user's password (which you are specifying, sodon't go looking for a key somewhere else). I recommend making thispassword fairly complex since once it is included in your code youwon't really need to remember it and it is also important enoughthat you want to protect it.

Web Services users are created in much the same way as another Magento user.

Web Services users arecreated in much the same way as another Magento user.

Assign the user a role using the check box that you will findunder the "User Role" tab on the left side of the page. Save theuser to complete the set up.

Access the Magento SOAP API

To access the Magento SOAP API, I am going to use a simple URIthat begins with the address of the Magento site you want toaccess. Note that you may or may not need index.php,depending on Magento's configuration.

Remember the key is to place /api/soap/?wsdl after theURL for the Magento site you want to access. If you try this in webbrowsers, even without authentication, you should get an XMLdocument describing the API structure.

To work with this API, I am going to write a short PHP script.This script begins by setting the URI described above as theargument for PHP's SoapClient function. Since I am usingthe SOAP extension for PHP, I need to make sure that it isinstalled and enabled on my server.

1<?php
2$client = newSoapClient('http://some_magento_store.com/index.php/api/soap/?wsdl');

I need to create a variable that includes the Magento webservice user and API key. I am using the login method fromthe Magento API. In the example, the username is "ArmandoRoggio"and the password or API key is"qg$<,VyQ62HJjQr3'dTxXC}bl4C/JuX#>P6U:16X-r&)Si}>m}pvzG_*rnpe(3"— remember, I suggested making this password complex.

1<?php
2$client = new SoapClient('http://some_magento_store.com/index.php/api/soap/?wsdl');
3$sessionId =$client->login('ArmandoRoggio','qg$<,VyQ62HJjQr3'dTxXC}bl4C/JuX#>P6U:16X-r&)Si}>m}pvzG_*rnpe(3`');

Next, I will use the API's call method to retrieve somedata from Magento. In this case, I am going to get the informationfor a product — it’s a new album from the band Cults. I will againuse the call method, providing it with the information setthat I want product.info and the product id.

1$result =$client->call($sessionId, 'product.info','1'  );

The results from this call will look something like thefollowing.

The results of an API call can be printed or further parsed.

The results of an API callcan be printed or further parsed.

Finally, it is a good idea to close the session when you'redone.

1$client->call('endSession',array($sessionId));

Using this same approach and Magento's many APImethods, one can access or update just about all of the dataavailable on the Magento platform. As a result, if you need toupdate product inventories from a warehouse receiving solution ormove Magento transactions to an account suite, this API may makethe process easy.

Summing Up

Magento offers a simple-to-use SOAP API for accessing customer,product, and transaction data. This API makes it easy to integratethe platform with third-party tools.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值