Webservice

Export data to remote service

Define data, connect to remote server and send/get data. Webservice settings are loaded from account preferences.

Read more on

Short example

$Invoice = $this->get('webservice','ekansio')->getResource('Invoice');

$Invoice->Number = '123456'}
$Invoice->Seller->Identifier        = '2318660-2';
$Invoice->Seller->Address->Street   = 'Sellerstreet 28';

$InvoiceLine->addInvoiceLine();
$InvoiceLine->ArticleIdentifier    = 'S-23456';
$InvoiceLine->ArticleName          = 'Product name';
$InvoiceLine->Quantity             = '2';
$InvoiceLine->Unit                 = 'pcs';
$InvoiceLine->VatRate              = '24';
$InvoiceLine->UnitPrice            = '100.00';

$Response = $Invoice->getResponse();

More detailed example

Load data

$date       = '2013-02-12';
$Employee   = $this->get('page','employee',$employeeId);
$WorkHours  = $this->get('pages','workhour')
    ->addWhere('date',$date)
    ->addWhere('employee',$employeeId);

Open the web service. Use settings defined in account preferences.

$Service  = $this->get('webservice','Netvisor');

If same webservice has multiple preferences, you can give the name of the parameter as 3rd parameter. As default, first preference is used.

$Service  = $this->get('webservice','Netvisor','test');

Load the needed resource from service:

$WorkDay  = $service->getResource('WorkDay');

Given export a name for webservice log:

$WorkDay->setLogTitle("Workhours ".$Employee->name." ".$date);

Set data to WorkDay -resource:

$WorkDay->Date                 = $date;
$WorkDay->EmployeeIdentifier   = $Employee->social_security_number;

foreach ( $WorkHours as $Workhour ){
    $Hour = $WorkDay->addWorkDayHour()}
    $Hour->Hours             = $Workhour->duration;
    $Hour->CollectorRatio    = '101';
    $Hour->AcceptanceStatus  = 'confirmed';
    $Hour->Description       = $Workhour->description;

    // Add a dimension
    $Hour->Dimension->DimensionName  = 'Project';
    $Hour->Dimension->DimensionItem  = $Workhour->project->number;

    // Add another dimension to Hour
    $Dimension = $Hour->addDimension();
    $Dimension->DimensionName  = 'Seller';
    $Dimension->DimensionItem  = $Workhour->project->seller->number;

    // Add reference to Workhour -page
    $Resource->addLogReference( $Workhour );
}

Get the content of

$xml = $WorkDay->getXmlString();

Stream file

$WorkDay->streamXmlFile();

Send data and take response:

$Response = $WorkDay->getResponse();

Or send data and get response values later:

$WorkDay->sendRequest();
if ( $WorkDay->getSuccess() ){
    $txt .= "Status: {$WorkDay->getStatus()}";
    $txt .= "Message: {$WorkDay->getMessage()}";
    $txt .= "Response: {$WorkDay->getResponse()}";
}

Webservice request

Most webservices are not specified as individual resources and parameters. Resources can be used via a generic request -object.

$Unifaun = $this->get('webservice','unifaun');
$Request = $Unifaun->newRequest('GET', 'shipments');
$data = $Request->getResponse();

Full method list

Webservice

Method return Description
newRequest([method,route,parameters,data]) WebserviceRequest Create new request object.

Set request values

Method return Description
setProtocol(string) this Set url protocol
setHost(string) this Set url host
setMethod(string) this Set HTTP METHOD
setRoute(string) this Set url path
setHeader(name,value) this Set header value
addParameter(name,value) this Add url parameter
addParameters(array) this Add multiple url parameter
setParameters(array) this Set url parameters
addData(name,value) this Add value to data
addData(array) this Add values to data
setData(array) this Set values to data

Get request values

Method return Description
getProtocol() string Get url protocol
getHost() string Get url host
getMethod() string Get HTTP METHOD
isMethod(string) bool Return TRUE if method is given argument
getRoute() string Get url path
getUrl() string
getHeaders() array Get request headers as array
getParameters() array Get url parameters as array
isParameters() bool Return TRUE, if has url parameters
getData() array Get data as array

Sending request

Method return Description
setDebug(bool) this If true, prints request info on screen.
sendRequest() - Send to request and sets response.
getSuccess() bool true if no errors.
isSuccess() bool True, if no errors.
getStatus() string Get response status.
getCode() string Get error code.
getMessage() string Get error message.
getResult() string RAW response string.
getInfo() string Request execution info.
getResponse() string Response data in array.