Skip to content

Instantly share code, notes, and snippets.

@bishwanathjha
Created June 10, 2020 07:39
Show Gist options
  • Save bishwanathjha/988da351ac590ebcba84211c73d78f38 to your computer and use it in GitHub Desktop.
Save bishwanathjha/988da351ac590ebcba84211c73d78f38 to your computer and use it in GitHub Desktop.
Create request/ticket on zendesk using API sample request
<?php
# To enable anonymous requests on zendesk so that you can create new request using API:
# - Sign in to Support and go to the Customers page (Admin > Settings > Customers).
# - Enable "Anyone can submit tickets".
# - Disable "Ask users to register".
$data = '{
"request": {
"requester": {
"name": "Bishwanath Jha",
"email": "bishwanathkj@gmail.com"
},
"subject": "Test ticket from Public API",
"comment": {
"body": "Test ticket from Public API!"
},
"custom_fields": [
{
"id": "36000060444",
"value": "custom_field_value_key"
},
{
"id": "11410032422",
"value": "custom_field_value_key"
}
]
}
}';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xxxxx.zendesk.com/api/v2/requests.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment