2

I would need to pass request payload in XML format for a web service. Below is the code I tried.

How do I verify & view XML is constructed properly?

Is there a better Magento way to create an XML request since a big payload needs to be constructed?

Note: object manager being is used for testing purposes

$xmlFactory=$obj->get('\Magento\Framework\Simplexml\ElementFactory');
    $xmlHeader = '<?xml version="1.0" encoding="UTF-8"?><OrderStatusQuery xmlns="http://some-schema"></OrderStatusQuery>';

    $request=$xmlFactory->create(['data'=>$xmlHeader]);
    $request->addChild("OrderNumbers","","");
    $request->addChild("OrderNumber","1234567");

    $http->setUri('https://some-external-api-endpoint');
    $http->setHeaders(['Content-Type: text/xml']);
    $http->setMethod(\Zend_Http_Client::POST);
    $http->setRawData($request);
    $responseBody = $http->request()->getBody();
    var_dump($responseBody);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.