skip to Main Content

I have an observer event that is capturing customer details anytime they are updated. At this point it posts that information to a var log.

I would like to get it to post to a SOAP API url.

SOAP API URL

at this point I am trying to be pointed in the right direction of how to do this, I believe I need to write the information into an XML that matches the API.
I only have 6 fields that need to be filled so I don’t think it will be to hard.

$fon = $billingaddress->getTelephone();
$street1 = $billingaddress->getStreet(1);
$street2 = $billingaddress->getStreet(2);
$city = $billingaddress->getCity();
$region = $billingaddress->getRegion();
$postcode = $billingaddress->getPostcode();

The phone number doubles as the customer #

Can somebody help me with the code to write the XML?

2

Answers


  1. This chunk will go inside your body tag, as shown in the examples HERE. For the XML, it is pretty straightforward, and you can do it as one $request variable instead of assigning several:

    <?php
    $request =  '<UpdateCustomer xmlns="http://www.dpro.com/DPAPIServices">'.
                  '<aRequest>'.
    //                  '<Username>'..'</Username>'.
    //                  '<Password>'..'</Password>'.
                    '<CustomerNumber>'.$billingaddress->getTelephone();.'</CustomerNumber>'.
                    '<CustomerName>'.$billingAddress->getFirstname().' '.$billingAddress->getLastname().'</CustomerName>'.
                    '<CustomerAddress1>'.$billingaddress->getStreet(1).'</CustomerAddress1>'.
                    '<CustomerAddress2>'.$billingaddress->getStreet(2).'</CustomerAddress2>'.
                    '<CustomerCity>'.$billingaddress->getCity().'</CustomerCity>'.
                    '<CustomerState>'.$billingaddress->getRegion().'</CustomerState>'.
                    '<CustomerZip>'.$billingaddress->getPostcode().'</CustomerZip>'.
                  '</aRequest>'.
                '</UpdateCustomer>';
    ?>
    

    NOTE:
    I commented out the Username and Password because they weren’t included in your example, and I am unsure whether they are your API user’s credentials or related to the Customer.

    Login or Signup to reply.
  2. You shouldn’t need to write any XML when working with a SOAP API that already exists. Use the built-in SoapClient.

    Have a look at the answers to this question if you need help with that: How to make a PHP SOAP call using the SoapClient class

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search