Skip to content

How to use Qualtrics REST API with PHP ?

About Qualtrics :Qualtrics API allows applications to integrate survey functionality, with specification of questions to ask, conditional display of questions depending on answers to prior questions, and aggregation and reporting of responses. It is intended to support academic research, customer service, preference polling, internal communications and employee feedback, and related functions. API methods support creation of survey questions with a range of response options, designation of survey recipients (either individuals or panels), questionnaire display, and logging of responses. Methods also support retrieval of response data for analysis outside the system.

In this post will show you, how i did REST calls to the Qualtrics REST API. Basically we need 3 things to access API. Need Access token you can find your token at your account settings page. And you the root URL for communicating with the Qualtrics system mine is https://xxx.qualtrics.com/WRAPI/ControlPanel/api.php and your user id.

Here is my PHP Class for all Qualtrics REST API calls.

user = $user;
        $this->token = $token;
        $this->basepath = $basepath;
        $this->format = $format;
        $this->version = $version;
        $this->requestDefaults = array('User' => $this->user,'Token' => $this->token,'Format' => $this->format ,'Version' => $this->version);
    }
    
    public function __call($name, $arguments) {
        return $this->request($name,$arguments);
    }      
        
    private function request($method,$params) {
        $method = array('Request' => $method);
        $params  = array_merge($this->requestDefaults,$params);
        $params  = array_merge($method,$params);
        $params = http_build_query($params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->basepath);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

}

How to use

Just pass the required details to the constructor method. By using generated object you can access qualtrics API methods.

$qualtrics = new Qualtrics('user_name','token','JSON','https://xxx.qualtrics.com/WRAPI/ControlPanel/api.php','2.4');

print_r($qualtrics->getSurvey(array('SurveyID' => 'SV_xxxxx')));

Methods and parameters are case sensitive in Qualtrics API.

Reference URLs :
https://survey.qualtrics.com/WRAPI/ControlPanel/docs.php

http://www.qualtrics.com/university/researchsuite/developer-tools/api-integration/qualtrics-rest-api/

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments