Documentation

Embed

Programmatic Filtering-PHP Code Example

Full code example for programmatic filtering using PHP


<?php
    $request = $_SERVER['REQUEST_URI'];
    if ($request == "/cards") {
        echo "Cameron";
    }
    else if ($request == "/card") {
        $secret='a3353b7bde6a9eb874f8961a0d6f4285basdbasdfasdfasdfasdf';
        $clientid='d68ea080-c1ef-4fab-8c38-aasdfasdfasdfasdf';
        $embedId = 'asdf5'; // 'asd45';

        $curl = curl_init();

        curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.domo.com/oauth/token?grant_type=client_credentials&scope=data%20user%20dashboard%20account",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_POSTFIELDS => "",
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
        CURLOPT_USERPWD => "$clientid:$secret"
        ));
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {
            echo "<br>cURL Error #: $err";
        }
        else {
            $responsearray = json_decode($response, true);
            $curl2 = curl_init();
            curl_setopt_array($curl2, array(
            CURLOPT_URL => "https://api.domo.com/v1/cards/embed/auth",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => '{
            "sessionLength": 1440,
            "authorizations" :[
                {
                "token" : "'.$embedId.'",
                "permissions" : ["READ", "FILTER", "EXPORT"],
                "filters" : [
                    {
                        "column": "State",
                        "operator": "IN",
                        "values": ["TX"]
                    }
                ]
                }
            ]
            }',
            CURLOPT_HTTPHEADER => array(
                "Authorization: Bearer ".$responsearray['access_token'],
                "Content-Type: application/json; chartset=utf-8",
                "Accept: */*"
            ),
            ));
            $response2 = curl_exec($curl2);
            $err2 = curl_error($curl2);
            curl_close($curl2);
            $responsearray = json_decode($response2, true);
            $embedToken = $responsearray['authentication'];
            $curl3 = curl_init();
            curl_setopt_array($curl3, array(
            CURLOPT_URL => "https://public.domo.com/embed/cards/$embedId",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_HTTPHEADER => array(
                "embedToken: ".$embedToken,
                "Accept: */*"
            ),
            ));
            $response3 = curl_exec($curl3);
            $err3 = curl_error($curl3);
            curl_close($curl3);
            $responsearray = json_decode($response3, true);
            http_response_code(200);
            echo <<<EOT
                <form id="form" action="https://public.domo.com/cards/$embedId" method="post">
                    <input type="hidden" name="embedToken" value="$embedToken">
                </form>
                <script>
                    document.getElementById("form").submit();
                </script>
            EOT;
        }
    }
    else {
        echo <<<EOT
        <html>
          <head>
            <title>Cameron</title>
          </head>
          <body>
            <hr>
            <div style="display: flex; flex-direction: column; width: 100%; justify-content: center; align-self: flex-start;">
                <div id="iframe-container" style="display: flex; justify-content: space-evenly; margin-top: 40px;">
                 Hello World
                 <iframe src="/card" width="600" height="600"></iframe>
                </div>      
            </div>
          </body>
        </html>        
        EOT;
    }
?>