dokNet.dk API


    Code example


    Hent pdf med resultat

    Du henter pdf med besvarelse for en respondent på adressen https://doknet.dk/api/respondent/resultpdf/{fid}/{sid}

    Eksempel ved hjælp af PHP og curl

    <?php
        // The authorization token
        $authorization = "Authorization: Bearer <token>";
     
        // Parameters
        $fid = '<fid>';
        $sid = '<sid>';
     
        // Setup cURL
        $ch = curl_init('https://doknet.dk/api/respondent/resultpdf/' . $fid . '/' . $sid);
        curl_setopt_array($ch, array(
          CURLOPT_RETURNTRANSFER => TRUE,
          CURLOPT_SSL_VERIFYPEER => false,
          CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', $authorization ),
        ));
     
        // Send the request
        $response = curl_exec($ch);
        $responseArray = json_decode($response, true);
        // Check for errors
        if($response === FALSE){
            die(curl_error($ch));
        }else if($responseArray['status'] == 400){
            echo $response . PHP_EOL;
        }else{
            $datetime = date("Ymd-His");
            $destination = "./result-" . $fid . "-" . $datetime . ".pdf";
            $file = fopen($destination, "w+");
            fputs($file, $response);
            fclose($file);
            // Print status from the response
            echo 'pdf downloaded' . PHP_EOL;
        }
    ?>