Action::getWebservice()

Version 2025.1

Return ActionIntegrationWebservice -object

Return value

Object ActionIntegrationWebservice

Example

Get webservice response

$response = $Action->getWebservice()->getResponse();

Full documentation

ActionWebservice CLASS

If you create an Integration -action, you can define the use of Webservice in ActionWebservice -object:

class eAccountActionWebserviceInvoice EXTENDS eActionIntegrationWebservice {
    protected $webservice = 'netvisor'; // Webservice name
    protected $connection = 'production'; // Connection name. default: first connection
    // 1. If webservice has resources
    protected $resource = 'SalesInvoice'; 
    // 2. If webservice request can be called directly
    protected $method = '';
    protected $route = '';

    protected $sendType = 'single'; // single/multiple. Selected pages in same request or create individual requests

    protected $test = true; // Create request but do not send it
    protected $debug = true; // Render debug information
    protected $log = true; // Save webservice log
    protected $errorEmail = ''; // Email to send error messages to

    function setData()
    {
        $Webservice = $this->getWebservice();
        $Lasku = $this->getPage();

        // 1. If webservice has resources
        $Invoice = $this->getResource();
        $Invoice->CustomerName = $Lasku->customer->getText();

        // 2. Call request
        $Request = $this->newRequest();
        $Request->addParameter('customer_name', $Lasku->customer->getText());
    }

    function onSendStart()
    {
        $Lasku = $this->getPage();
        $Lasku->vientipaiva = 'Today';
    }

    function onSuccess()
    {
        $Lasku = $this->getPage();
        $response = $this->getResponse();

        $Lasku->tila = 'Laskutettu';
        $Lasku->invoice_number = $response['invoice']['invoice_number'];
    }

    function onSendReady()
    {
        $Lasku = $this->getPage();    
        if ( !$this->isTest() ){
            $Lasku->save();
        }
    }

}

Using ActionWebservice

Using ActionWebservice in app

When Integration -action is defined to be visible in page menu, it can be run to selected pages(s). Opens a new window and executes Webservice render() -method. (Send request(s) and renders feedback).

Usin ActionWebservice in code

You can run ActionWebservice request using Actions execute() -method:

$OrderPage->getAction('create_order')->execute();

Or you can run it and get feedback using tulosta() -method:

$OrderPage->getAction('create_order')->tulosta();

You can get the ActionWebservice -object for more precise use:

$Webservice = $Action->getWebservice(); // Last AccountWebservice (if executed multiple pages)
if ( $Webservice->getSuccess() ){
    $data = $Webservice->getResponse();
}
if ( $Webservice->isError() ){
    $messages = $Webservice->getMessages(); // All messages
    $errors = $Webservice->getErrors(); // Just error messages
}

NOTE! If you need to make changes to a page after a successfull request, you should do it inside AccountWebservice->onSuccess().

Full method list

Method return Description
setTest(bool) this Set test. If TRUE, does not send the actual request.
setLog(bool) this Set log. If true, saves log for request.
setDebug(bool) this Set debug. If TRUE, renders additional info
addParameter(name,value) this Set request parameter
addParameters(array) this Add request parameters
setHeader(name,value) this Set request header
getPage(Page) this Set page webservice is run against
getPages(Pages) this Set pages webservice is run against
setErrorEmail(string) this Set email to send error messages to.
sendRequest() bool Return TRUE if request sent with no errors

Hook methods

Method return Description
init() void Run after ActionWebservice -object is created
initWebservice($webservice) void Modify Webservice -object after created.
initResource($Resource) void Modify WebserviceResource -object after created.
initRequest($Request) void Modify WebserviceRequest -object after created.
setData() void Set data to request object
onSendStart() void Executed before request is sent
onSuccess() void Executed after request is sent and no errrors
onError() void Executed after request is sent and was error
onSendReady() void Executed after request is sent

Request info:

Method return Description
isTest() bool Return TRUE if test is TRUE
isDebug() bool Return TRUE if debug is TRUE
isLog() bool Return TRUE if log is TRUE
getDebug() bool Get TRUE, if debug
getLog() WebserviceLog WebserviceLog -object
getSendType() string Return send type: single/multiple
getMethod() string Request HTTP method
getProtocol() string Request http protocol
getHost() string Base url
getRoute() string Request route
getUrl() string Request url
getParameters() array Request parameters
isParameter(name) bool Return true, if parameter with name is defined
getData() array Get request data
getHeaders() array Get Request parameters
isErrorEmail() true Return TRUE if error email is set.
getErrorEmail() string Get error email.
sendErrorEmail() this Send error message. (Is sent if error occured)
isError() bool Return TRUE if webservice has errors
getErrors() array Get error messages [title, type]
getMessages() array Get all messages [title, type]
isPage() bool Return TRUE webservice has Page
getPage() Page Get page webservice is run against
getPages() Pages Get all pages webservice is run against
getAction() Action Get action -object
getWebservice() Webservice Get webservice object
getResource([name]) WebserviceResource Get resource -object. Default: as defined in CLASS. If arguments: Create new custom Resource
isResource() bool Webservice has default resource
getRequest([method,route,params,data]) WebserviceRequest Get request -object. Default: as defined in CLASS. If arguments: Create new custom Request
getRequestObject() WebserviceRequest Get Request -object that makes the actual request (Resource->Request or Request)

Request response:

Method return Description
getResponse() Array Response data
getResult() string Original response content
isSuccess() bool Return TRUE if request sent with no errors
render() html Send request end render info