Skip to main content
Version: 2.2.1

PHP example

Example of PHP for use in applications located externally to SoftExpert Suite​

API key​

To connect to one of our SOAP web services using an external PHP file, we recommend using the SOAP extension, which is native to PHP. This extension provides an easy and efficient way to connect to SOAP web services and interact with them directly from the PHP code. It is important to note that the SOAP extension is a standard PHP library since version 5 and does not require additional installation. Below is an example of how to use the SOAP extension to connect to a SOAP web service:

<?php
// Server domain or server ip
$server = "my-domain.softexpert.com";

//Local WSDL File (in this sample we are using SE Administration WebService)
//$wsdl = "adm_ws.wsdl";
//URL to download a remote WSDL
$wsdl = "https://$server/se/ws/adm_ws.php?wsdl";

//endpoint to connect
$location = "https://$server/apigateway/se/ws/adm_ws.php";

//Http request context (you should set the Authorization Token). In context details you can disable ssl feature (https://www.php.net/manual/pt_BR/context.ssl.php)
$context = array(
'http' => array(
'header' => 'Authorization: userToken' //user token captured in your sesuite account details
));

$client = new SoapClient($wsdl, array(
"trace" => 1, // enable trace
"exceptions" => 1, // enable exceptions
"stream_context" => stream_context_create($context),
"location" => $location
));

//below we are using a sample method in SE Administration WebService
$return = $client->editPosition(array(
'ID' => "SamplePosition",
'DESC' => "SamplePosition"
));

It is possible to ignore the SSL protocol in this context just by changing the value of the context variable. According to the example below:

//Http request context (you should set the Authorization Token). In context details you can disable ssl feature (https://www.php.net/manual/pt_BR/context.ssl.php)
$context = array(
'http' => array(
'header' => 'Authorization: userToken'
),

'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)

);
tip

  Tip: You must have enabled the SOAP and OpenSSL extensions within the settings of the PHP (php.ini) used from your application.

Example of PHP for using automations in SoftExpert Suite​

If you need to connect to one of our web services using an internal SoftExpert Suite file (such as an external application, for example), we can simplify the process using a method we have developed specifically for this purpose. Below is an example of this call, which can be inserted into the source code of the respective external application:

//classe SoapGateway is located inside of /include/dataintegration/apigateway/class.SoapGateway.inc
$soapGateway = new SoapGateway("user_token_here", "my-domain.softexpert.com");
$return = $soapGateway->call();

See below the record of the call() method mentioned above to express the possible parameters and their functionality.

/**
* Method that calls a method from the respective SoftExpert Suite SOAP web service.
* @param String $params Array containing the request structure.
* @param String $resourcePath Path of the web service to be called. It is usually similar to se/ws/<component_code>_ws.php. E.g.: se/ws/adm_ws.
* @param String $soapAction Method that will be called in the respective web service.
*/

public function call($params = array('ID' => "SamplePosition", 'DESC' => "SamplePosition"), $resourcePath = "se/ws/adm_ws.php", $soapAction = "editPosition")

Basic Auth​

To create the PHP connection file, you must include the WSDL address for the connection using the location tag. See the example below:

// URL do WSDL
$wsdl = "https://$server/se/ws/dc_ws.php?wsdl";
$location = "https://$server/apigateway/se/ws/conteudo.php";

// Instances a SOAP client
$client = new SoapClient($wsdl,array(
"trace" => 1, // Enables trace
"exceptions" => 1, // Treats exceptions
"login" => $user,
"password" => $pass,
"stream_context"=>stream_context_create($context),
"location" => $location
));