Search code examples
phpsoapwsdl

SOAP request with PHP


I need some help to get started with a SOAP API. I have to implement a API for a vacancy section of a clients website.

I need to implement the SOAP API via PHP. Do I need to ask for a WSDL file? Or is the included documentation sufficient for calling the api

The documentation describes the following:

GetAllJob
Returns a list of search results. Get requests only.

Parameters

&DeveloperKey=

  - Required

&CustomerId=

  - Required, numeric only

&Keywords=

  - Optional, string, must be URL encoded
  - Can accept a single value, or a comma-separated list of values

&Location=

  - Optional, string, must be URL encoded
  - Can accept a single city name, a postal code or a comma-separated city

&Category=

  - Optional, numeric (Category code)
  - Can accept a single value only.
  - If the given value do not match any of category codes, this parameter is ignored. We do not attempt any partial matching
  - Reference the Categories service for a complete list of valid category names and codes

&EducationLevel=

  - Optional, numeric (Education level code)
  - Can accept a single value only.
  - Reference the Education level service for a complete list of valid education level names and codes

Sample Output http://piratepad.net/soap-xml-sample-output


Solution

  • I'd recommend using the Zend_Soap_Client, a popular library for connecting to SOAP APIs.

    This is a pretty decent tutorial which explains how to use the library. If you are using composer for dependancy management (which is highly recommended), you can bypass the installation instructions and just install the package zendframework/zend-soap.

    The basis steps are:

    Instantiate a new Zend_Soap_Client, passing the WSDL so the client so it is aware of the methods + parameters of the API.

    $this->soapClient = new Zend_Soap_Client(
        'http://url.to.your.api.com?WSDL'
    );
    

    Call a method available to you, passing any required parameters, then fetch the result property. So for GetAllJob, its likely to be:

    $allJobs = $this
        ->soapClient
        ->GetAllJob($parameters)
        ->GetAllJobResult
    ;
    

    Once you're getting some data back, look to integrate the soap client into your wider application.