PHP code example of qualiaanalytics / php-api

1. Go to this page and download the library: Download qualiaanalytics/php-api 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/ */

    

qualiaanalytics / php-api example snippets


// Import library from composer

$client = new \Qualia\Client("YOUR_SURVEY_ID", "API_KEY");

$response = \Qualia\Submission\Entry::build($client)
                                  ->name("QUESTION_ID", "First Name", "Last Name")
                                  ->email("QUESTION_ID", "[email protected]")
                                  ->date("QUESTION_ID", "2020-01-02")
                                  ->response("QUESTION_ID", "RESPONSE")
                                  ->send();

$response = \Qualia\Submission\Entry::build($client)
                                  ->uniqueId("123")
                                  ...
                                  ->send();

$response = \Qualia\Submission\Entry::build($client)
                                  ...
                                  ->language("en")
                                  ->send();

$response = \Qualia\Submission\Entry::build($client)
                                  ->allowDuplicates()
                                  ...
                                  ->send();

$questions = \Qualia\Configuration\Questions::get($client);

var_dump($questions);
/*
    [
        "surveys": [
            [ "name": "Enrollment Survey","key": "enrollment"],
            [ "name": "Initial Survey","key": "initial_survey"], 
        ],
        [
            key: "QUESTION_ID",
            name: "Question Name"
            type: "Question Type",
            options: [
                OPTION_ID: "Option #1 name",
                OPTION_ID: "Option #2 name",
                ...
            ],
            help: "guidance which method to use"
        ],
        [
            key: "q_BFmVBf1TSb11xAU0",
            name: "What's your date of Visit?"
            type: "date",
            options: [ ],
            help: "use date("q_BFmVBf1TSb11xAU0", "2020-01-02") method in API Client. Date Value must be provided in Y-m-d."
        ],
        ...
    ]
*/
                              

// Import library from composer
 new \Qualia\Client("YOUR_SURVEY_ID", "API_KEY");

try {
    // Create entry
    $response = \Qualia\Submission\Entry::build($client)
                                        ->uniqueId("SOME_ID")
                                        ->name("QUESTION_ID", "First Name", "Last Name")
                                        ->email("QUESTION_ID", "[email protected]")
                                        ->date("QUESTION_ID", "2020-01-02")
                                        ->response("QUESTION_ID", "RESPONSE")
                                        ->send();
} catch (\Qualia\Exceptions\ConnectionErrorException $e) {
    // unable to connect to server
} catch (\Qualia\Exceptions\EmailExistsException $e) {
    // echo $e->getEntryId();
    // The submitted email already exists in the server.
    // You may or may not need to handle this in your code..
    // By default, we are preventing duplicate submissions,
    // if you would like to submit it otherwise, call
    // allowDuplicates() method when building an entry
} catch (\Qualia\Exceptions\RequestException $e) {
    // some other unexpected error
    // echo $e->getMessage();
}

composer