API/Example: PHP

From wiki

Example: PHP

[edit]

This example demonstrates how to use the **Verofy API** from PHP with the Yii HTTP Client.

Overview

[edit]

The example covers:

  • Authenticating via refresh and access tokens
  • Retrieving a list of map sites filtered by `externalId`
  • Updating a map site record by ID

Ensure that the **Yii HTTP Client** component is installed and properly configured.


Example Script

[edit]
<?php

use yii\httpclient\Client;

$client = new Client([
    'baseUrl' => "https://apidev.verofy.veronetworks.com/v1",
]);

$refreshToken = getRefreshToken($client);
$accessToken  = getAccessToken($client, $refreshToken);

// ------------------------------------------------------------
// Example #1: Get a list of map sites filtered by externalId
// ------------------------------------------------------------
$externalId = 1002;
$mapPointId = null;

$rs = $client->createRequest()
    ->setMethod('GET')
    ->setUrl('/map-site?filter[externalId]=' . $externalId)
    ->setHeaders(['Authorization' => 'Bearer ' . $accessToken])
    ->send();

foreach ($rs->data['items'] as $item) {
    if (isset($item['externalId']) && $item['externalId'] == $externalId) {
        // We found the specific map site by its externalId
        $mapPointId = $item['id'];
    }
}

// ------------------------------------------------------------
// Example #2: Update map point by its ID
// ------------------------------------------------------------
$request = $client->createRequest()
    ->setMethod('PATCH')
    ->setUrl("map-site/update?id={$mapPointId}")
    ->setFormat(Client::FORMAT_JSON)
    ->setHeaders([
        'Authorization' => 'Bearer ' . $accessToken,
        'Accept'        => 'application/json',
    ])
    ->setData([
        'latitude'  => 34.00,
        'longitude' => 33.00,
        'name'      => 'John Doe',
        'address1'  => '3551 Poppi Ave, Evans, CO 80620',
        // Additional attributes...
    ]);

// Send the request
$response = $request->send();

Notes

[edit]
  • Replace getRefreshToken() and getAccessToken() with your own authentication logic.
  • Always store tokens securely and avoid committing them to source control.
  • The examples assume your API instance is reachable at
 https://apidev.verofy.veronetworks.com/v1  
 — adjust to your environment if needed.  

Next:API/Endpoint Documentation