Search code examples
phpweb-servicessoap-client

PHP SOAPCall Input is null


I'm getting the following error:

Fatal error: Uncaught SoapFault exception: [s:Client] Service operation Pickup_Cancel failed due to validation errors: Input is null

Here's my code:

$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl", array("trace" => 1, "exception" => 0));

$params = array(
        "CodeStation" => `BEY`,
        "PickupNumber" => `1`,
        "Reason" => `test reason`,
        "Password" => `sss`,
        "ShipperAccount" => `acc`,
        "UserName" => `acc`,
    );

$client->Pickup_Cancel($params);

Solution

  • The awnser to the question you didn't ask is probably: replace the backticks (`) by singlequotes (')

    -- Edit. That was not the problem.

    Here is the case. SOAP can be a pain to get going. My experience is to use a good soap class or just non-wsdl mode. Read up on this in the docs: https://www.php.net/manual/en/soapclient.soapcall.php

    So don't do this:

    $return = $soapClient->functionName($data);
    

    But this:

    $return = $soapClient->__SoapCall('functionName', $data);
    

    Also get a grip on what the server wants, load the WSDL url into a client like SoapUI https://www.soapui.org/ (its free). This lets you check if the SoapServer works and how you should approach it with your call.

    In your case the WSDL states this:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pos="http://schemas.datacontract.org/2004/07/PostaWebClient">
       <soapenv:Header/>
       <soapenv:Body>
          <tem:Pickup_Cancel>
             <!--Optional:-->
             <tem:CLIENTINFO>
                <!--Optional:-->
                <pos:CodeStation>asd</pos:CodeStation>
                <!--Optional:-->
                <pos:Password>asd</pos:Password>
                <!--Optional:-->
                <pos:ShipperAccount>asd</pos:ShipperAccount>
                <!--Optional:-->
                <pos:UserName>asd</pos:UserName>
             </tem:CLIENTINFO>
             <!--Optional:-->
             <tem:PickupNumber>asd</tem:PickupNumber>
             <!--Optional:-->
             <tem:Reason>asd</tem:Reason>
          </tem:Pickup_Cancel>
       </soapenv:Body>
    </soapenv:Envelope>
    

    Which translates to this PHP code:

    $client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl");
    
    $params = [
        'Pickup_Cancel' => [
            'CLIENTINFO' => [
                'Password' => 'sss',
                'ShipperAccount' => 'acc',
                'UserName' => 'acc',
                'CodeStation' => '',
            ],
            'PickupNumber' => '',
            'Reason' => '',
        ],
    ];
    
    $client->__SoapCall("Pickup_Cancel", $params);
    

    See how the array matches the WSDL xml format?

    This should also give you the feedback you need to proceed. If not, its probably time to get 'real' help :) Goodluck.