Consume Nav WebService CodeUnit with Php

You can find plenty information over internet to consume nav web service but lot of them need modification for working in your case. I provide you a Php code to consume Nav Codeunit by SOAP Webservice tested and working.

Nav part :

– Create a codeunit with public method you want to be accessible.
– Publish the code unit with “Web service” page (simply create a new line with the Cu n° and tick “published”)
– Create a specific not windows user in Nav and create him a web service access key
– Define the user permission (you can set it to super if you control the service published)
For the php part you’ll need to provided the SOAP address of the code unit, the user/access key created. You can also provide the code unit methods et parameters to call (this can be retrive in the web service WSDL).

Php part :

You’ll need to have the Soap extention installed on your php server to run following code.
NB : Code unit paramaters are case sensitive this can throw you the “Parameter in method is null” error if they’re not provided exactly same as in the Nav code unit.

Consume Nav CodeUnit


if (extension_loaded('soap'))
    // Request parameters :
    // Exemple is a Nav Code unit GetSalesPrices, method GetPrice(CodPCustomerNo, CodPItemNo)
    $NavAccessKey = "wGEbboEIdKgEPzE0N0vuuVE/2e/0lzvCsTtB9n9L7KI=";
    $CodeunitMethod = "GetPrice";
    $params = array(
        "CodPCustomerNo" => "CUSTOMER_1",
        "CodPItemNo" => "ITEM_1",

    // SOAP request header
    $url = "";
    $options = array(
        'authentication' => SOAP_AUTHENTICATION_BASIC,
        'login' => $NavUsername,
        'password' => $NavAccessKey,
        'trace' => 1,
        'exception' => 0,

        $client = new SoapClient($url, $options);
        $soap_response = $client->__soapCall($CodeunitMethod, array('parameters' => $params));
        echo "SOAP REQUEST SUCESS :";
    catch (SoapFault $soapFault)
        echo "SOAP REQUEST FAILED :<br>";
        echo "Request :<br>" . htmlentities($soap_client->__getLastRequest()) . "<br>";
        echo "Response :<br>" . htmlentities($soap_client->__getLastResponse()) . "<br>";
    echo "Php SOAP extention is not available. Please enable/install it to handle SOAP communication.";


This code simply show the request result with echo to see if it’s ok, but you can directly handle result value with $soap_response->return_value


  1. Good Morning,

    I try your code but I receive an error like: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘ and so on… Can you help me to hunderstand why it happen? thank you

Leave a Reply

Your email address will not be published. Required fields are marked *