PHP

This example makes use of the cURL extension for PHP. This extension must be enabled in your PHP configuration to use it.

<?php

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,  "https://www.sandbox.vertalo.com/authenticate/token/discovery");
    curl_exec($ch);
    curl_close($ch);

    //
    // Get LOGIN access token...
    //
    $client_id = "<your client ID>";
    $client_secret = "<your client secret>";
    curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.vertalo.com/authenticate/token/login?client_id=$client_id&client_secret=$client_secret");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $response = json_decode($response, true);
    $access_token = $response["token"]["access_token"];
    $users_account_id = $response["roles"]["data"][0]["users_account_id"];
    // print("$access_token\n");
    // print("$users_account_id\n");

    //
    // Get ROLE access token...
    //
    if ($access_token && $users_account_id) {
        $headers = array();
        $headers[] = "Authorization: Bearer $access_token";
        curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.vertalo.com/authenticate/token/role/$users_account_id");
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);

        $response = json_decode($response, true);
        $access_token = $response["token"]["access_token"];
        // print("$access_token\n");

        //
        // Execute GraphQL query...
        //
        if ($access_token) {
        $headers = array();
        $headers[] = "Authorization: Bearer $access_token";
        $headers[] = "Content-Type: application/json; charset=utf-8";
        $query = '{"query": ' .
        '"query {' .
            'allAssets {' .
                'nodes {' .
                    'id ' . 
                    'name ' .
                    'type ' .
                '}' .
            '}' .
        '}"' .
    '}';

    curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.vertalo.com/token/api/v2/graphql");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    $response = curl_exec($ch);

    $response = json_decode($response, true);
    var_dump($response);

   }
 }
 curl_close($ch);

?>
What's on this Page