Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
cb17ff51
Commit
cb17ff51
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
api: Add example script to create tickets
parent
bd0169ba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
setup/scripts/api_ticket_create.php
+63
-0
63 additions, 0 deletions
setup/scripts/api_ticket_create.php
with
63 additions
and
0 deletions
setup/scripts/api_ticket_create.php
0 → 100755
+
63
−
0
View file @
cb17ff51
#!/usr/bin/php -q
<?php
#
# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
#
$config
=
array
(
'url'
=>
'http://domain.com/api/tickets.json'
,
'key'
=>
'<api key>'
);
# Fill in the data for the new ticket, this will likely come from $_POST.
$data
=
array
(
'name'
=>
'John Doe'
,
'email'
=>
'mailbox@host.com'
,
'subject'
=>
'Test API message'
,
'message'
=>
'This is a test of the osTicket API'
,
'ip'
=>
$_SERVER
[
'REMOTE_ADDR'
],
'attachments'
=>
array
(),
);
/*
* Add in attachments here if necessary
$data['attachments'][] =
array('filename.pdf' =>
'data:image/png;base64,' .
base64_encode(file_get_contents('/path/to/filename.pdf')));
*/
#pre-checks
function_exists
(
'curl_version'
)
or
die
(
'CURL support required'
);
function_exists
(
'json_encode'
)
or
die
(
'JSON support required'
);
#set timeout
set_time_limit
(
30
);
#curl post
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$config
[
'url'
]);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
json_encode
(
$data
));
curl_setopt
(
$ch
,
CURLOPT_USERAGENT
,
'osTicket API Client v1.7'
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
FALSE
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
array
(
'Expect:'
,
'X-API-Key: '
.
$config
[
'key'
]));
curl_setopt
(
$ch
,
CURLOPT_FOLLOWLOCATION
,
FALSE
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
TRUE
);
$result
=
curl_exec
(
$ch
);
$code
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
curl_close
(
$ch
);
if
(
$code
!=
201
)
die
(
'Unable to create ticket: '
.
$result
);
$ticket_id
=
(
int
)
$result
;
# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment