PHP code example of art-pub / nfon-api-client-php

1. Go to this page and download the library: Download art-pub/nfon-api-client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

art-pub / nfon-api-client-php example snippets


    ...
    use NFONAPIClient\client;
    ...
    $apiBasePath = "https://api09.nfon.com"; // <-- insert the API base path provided by NFON
    $apiKey      = "NFON-KEY"; // <-- insert the API key provided by NFON
    $apiSecret   = "NFON-SECRET"; // <-- insert the API secret here
    $account     = "NFON-ACCOUNT"; // <-- insert the account name here
    $path = "/api/customers/" . $account . "/phone-books";
    $method = "GET";
    $body = "";
    $contentType = "application/json";

    // calculate the signature
    [$requestDate, $requestContentType, $requestContentMD5, $signature] = client::getAuthentication($path, $apiSecret, $method, $body, $contentType);

    // make the request
    [$response, $success] = client::request(
            apiBasePath: $apiBasePath,
            apiKey: $apiKey,
            signature: $signature,
            method: $method,
            path: $path,
            apiDate: $requestDate,
            contentMD5: $requestContentMD5,
            body: $body,
            contentLength: strlen($body),
            contentType: $requestContentType,
            apiHeaders: [], // <-- you can add additional request headers here
        );
    if ($success) {
        print_r($response);
        print PHP_EOL;
    } else {
        print "ERROR: $response".PHP_EOL;
    }
    ...