Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How to Get Order & Customer Information By Magento 2 SOAP API

Vinh Jacker | 06-21-2024

How to Get Order & Customer Information By Magento 2 SOAP API

SOAP API in Magento 2 is an application programming interface based on the SOAP (Simple Object Access Protocol) protocol, making it easy for developers to access and manage data on the system. Using the SOAP API not only helps automate processes but also enhances the efficiency of managing order and customer information.

In this article, we will guide you through the simple steps to get customer information and order information using the SOAP API in Magento 2.

Make sure the SOAP APIs are enabled and properly configured in your Magento 2 instance.

Steps to Get Order Information Using SOAP API in Magento 2

When you need to create a mobile application for your Magento website, you will need order information from outside the store, and the SOAP API will help you with this.

To get order information using SOAP API in Magento 2, create a file called call_soap.php and add the following code:

<?php

$request = new SoapClient("http://<magento_host>/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2));

// changes your store url.
$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin2", "password"=>"admin123"));

$request = new SoapClient(
    'http://<magento_host>/soap/default?wsdl&services=salesOrderRepositoryV1',
    array(
        'soap_version' => SOAP_1_2,
        'stream_context' => stream_context_create(array(
            'http'=> array('header' => 'Authorization: Bearer '.$token->result)
        ))
    )
);
// changes your store url.

$response = $request->SalesOrderRepositoryV1Get(array('id' => 1));

var_dump($response);

?> 

With just one step, you can get order information using the SOAP API in Magento 2. Additionally, the SOAP API can help you maintain products and inventory for your Magento 2 store. Integrate the SOAP API to synchronize inventory for Magento 2 to achieve this.

Steps to Get Customer Information Using SOAP API in Magento 2

Similar to getting order information, you can also get customer information using the SOAP API in Magento 2.

To do this, create a file named call_soap.php and enter the code below:

<?php
$request = new SoapClient("http://<magento_host>/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2));
// changed your store url.
$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin", "password"=>"admin@1234"));

$request = new SoapClient(
    'http://<magento_host>/soap/default?wsdl&services=customerCustomerRepositoryV1',
    array(
        'soap_version' => SOAP_1_2,
        'stream_context' => stream_context_create(array(
            'http'=> array('header' => 'Authorization: Bearer '.$token->result)
        ))
    )
);
// you need pass customer id in array
$response = $request->customerCustomerRepositoryV1GetById(array("customerId" => 3));
echo "<pre>";
print_r($response);
echo "</pre>";


?>

In this way, you can easily get detailed customer information using the SOAP API in Magento 2.

Conclusion

Retrieving customer and order information using the SOAP API in Magento 2 not only helps automate the management process but also enhances efficiency and accuracy in data management.

We hope that through this article, you have grasped the basic steps to perform API requests and integrate them into your system effectively.

If you encounter any difficulties during the implementation process, do not hesitate to contact us for support.

Table of content
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services