I am struggling to get the Qualtrics PUT API to work using PHP.
The cURL syntax is:
curl -X PUT -H 'X-API-TOKEN: yourtokenhere' -H 'Content-Type: application/json' -d '{
"status": "active",
"lastName": "ExampleLastName",
"password": "uwillneverguess",
"firstName": "ExampleFirstName",
"userType": "UT_1234567890AbCdE",
"accountExpirationDate": null,
"permissions": {
"controlPanel": {
"accountPermissions": {
"accessApi": {
"state": "off"
}
}
}
}
}' 'https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE'
I need this to work in PHP. I am trying to update the password only. I would appreciate any help as I've been trying for a while with no success.
Qualtrics doesn't provide any example PHP code but the following additional information might help:
Request Headers
Accept: */*
X-API-TOKEN: yourtokenhere
accept-encoding: gzip, deflate
content-type: application/json
content-length: 24
Request Data
{
"password": "Password1"
}
Thanks in advance.
Below is a sample php example based on your curl example.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"status\": \"active\",
\"lastName\": \"ExampleLastName\",
\"password\": \"uwillneverguess\",
\"firstName\": \"ExampleFirstName\",
\"userType\": \"UT_1234567890AbCdE\",
\"accountExpirationDate\": null,
\"permissions\": {
\"controlPanel\": {
\"accountPermissions\": {
\"accessApi\": {
\"state\": \"off\"
}
}
}
}
}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Api-Token: yourtokenhere";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Thanks to Abhinav Verma for the answer:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, "https://yourdatacenterid.qualtrics.com/API/v3/users/UR_1234567890AbCdE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"status\": \"active\",
\"lastName\": \"ExampleLastName\",
\"password\": \"uwillneverguess\",
\"firstName\": \"ExampleFirstName\",
\"userType\": \"UT_1234567890AbCdE\",
\"accountExpirationDate\": null,
\"permissions\": {
\"controlPanel\": {
\"accountPermissions\": {
\"accessApi\": {
\"state\": \"off\"
}
}
}
}
}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Api-Token: yourtokenhere";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);