osticket-api icon indicating copy to clipboard operation
osticket-api copied to clipboard

Getting 500 Internal Server Error

Open dgomiller opened this issue 1 year ago • 6 comments

I've put the ost_wbs folder into the "upload" folder as that appears to be where OSTicket pulls from. Because of this I have to use hosturl/ost_wbs instead of what it says in the document as hosturl/upload gives me a 404.

That being said, it seems to work... kind of. If I don't have an API key in the header it tells me it's an "Incorrect API Format", but when I have the API key and try to run it it gives me the 500 server error and the body is blank, nothing returned at all.

I am attempting to get a specific user using POSTMAN. I copied the code from the documentation site into the Body tab, using "raw" and "json"

{ "query":"user", "condition":"specific", "sort":"email", "parameters":{ "email":"[email protected]" } }

and in the headers tab I put "apikey" with a value of the API key generated with my computer's IP address.

Any help would be appreciated.

dgomiller avatar May 07 '24 20:05 dgomiller

The "upload" folder is simply a reference to the directory where your osTicket is installed. For example, if your osTicket is located at http://127.0.0.1/osticket/, then the "upload" folder refers to the "osticket" directory. Another example is if your osTicket is located at http://127.0.0.1/support/, then the "upload" folder refers to the "support" directory.

Also here is an example of how to query for a specific user by email using PHP:

<?php

// API endpoint
$url = 'http://127.0.0.1/support/ost_wbs';

// API key
$apiKey = 'Whatever the api key is';

// Data to be sent in the request
$data = [
    'query' => 'user',
    'condition' => 'specific',
    'sort' => 'email',
    'parameters' => [
        'email' => '[email protected]'
    ]
];

$jsonData = json_encode($data);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'apikey: ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($ch);

if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    die('cURL error: ' . $error);
}

curl_close($ch);

echo 'Response: ' . $response;

At0kir avatar May 14 '24 17:05 At0kir

Running into a similar error; attempting to send a web request through unity; i ensured that my apikey is correcly configured and the json parameters as the body but it keeps giving me internal 500 error. Here's my unity web request:

string jsonData = JsonUtility.ToJson(ticketJsonData, true); Debug.Log("JSON :" + jsonData); // Create the UnityWebRequest UnityWebRequest request = new UnityWebRequest("https://www.support.futurecolossal.com/ost_wbs", "POST"); byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData); request.uploadHandler = new UploadHandlerRaw(bodyRaw); request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("apikey", "F41E8DBC5746E01231655AAD0FA1A9E1");

	// Send the request
	yield return request.SendWebRequest();

	if (request.result == UnityWebRequest.Result.Success)
	{
		Debug.Log("Ticket created successfully!");
		Debug.Log("Response: " + request.downloadHandler.text);
	}
	else
	{
		Debug.LogError("Error creating ticket: " + request.error);
	}

Jill1995 avatar Jun 10 '24 19:06 Jill1995

For some reason it fails to load the classes. This seems to be because the class includes are all lower case but its trying to find them with upper case included. e.g. DBConnection, but the class is dbconnection. Changed as below and all working now. - this isn't a fix and its not been fully tested, just got me going.

spl_autoload_register( function ( $class ) {
    require_once 'classes/class.' . strtolower($class) . '.php';
});

Yet, the classes are all lower case. At least in my case they are.

FWI there are also a lot of depreciated warnings on PHP 8.3, so that'll need fixing at some point.

GENnetuk-DEV avatar Jul 10 '24 11:07 GENnetuk-DEV

The "upload" folder is simply a reference to the directory where your osTicket is installed. For example, if your osTicket is located at http://127.0.0.1/osticket/, then the "upload" folder refers to the "osticket" directory. Another example is if your osTicket is located at http://127.0.0.1/support/, then the "upload" folder refers to the "support" directory.

Also here is an example of how to query for a specific user by email using PHP:

<?php

// API endpoint
$url = 'http://127.0.0.1/support/ost_wbs';

// API key
$apiKey = 'Whatever the api key is';

// Data to be sent in the request
$data = [
    'query' => 'user',
    'condition' => 'specific',
    'sort' => 'email',
    'parameters' => [
        'email' => '[email protected]'
    ]
];

$jsonData = json_encode($data);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'apikey: ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($ch);

if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    die('cURL error: ' . $error);
}

curl_close($ch);

echo 'Response: ' . $response;

This example seems to work great, other than I'm getting a 301 error - any guesses why? I seem to be hitting my endpoint correctly.

HeartlandCyber avatar Feb 05 '25 21:02 HeartlandCyber

The "upload" folder is simply a reference to the directory where your osTicket is installed. For example, if your osTicket is located at http://127.0.0.1/osticket/, then the "upload" folder refers to the "osticket" directory. Another example is if your osTicket is located at http://127.0.0.1/support/, then the "upload" folder refers to the "support" directory. Also here is an example of how to query for a specific user by email using PHP:

<?php

// API endpoint
$url = 'http://127.0.0.1/support/ost_wbs';

// API key
$apiKey = 'Whatever the api key is';

// Data to be sent in the request
$data = [
    'query' => 'user',
    'condition' => 'specific',
    'sort' => 'email',
    'parameters' => [
        'email' => '[email protected]'
    ]
];

$jsonData = json_encode($data);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'apikey: ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($ch);

if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    die('cURL error: ' . $error);
}

curl_close($ch);

echo 'Response: ' . $response;

This example seems to work great, other than I'm getting a 301 error - any guesses why? I seem to be hitting my endpoint correctly.

I don't recommend using this GitHub repo anymore as it was written for osticket 1.17.

OsTicket is now on version 1.18 which most likely made some changes to the API which is causing these issues. I don't use OsTicket anymore so I cannot help you with this issue.

At0kir avatar Feb 05 '25 21:02 At0kir

The "upload" folder is simply a reference to the directory where your osTicket is installed. For example, if your osTicket is located at http://127.0.0.1/osticket/, then the "upload" folder refers to the "osticket" directory. Another example is if your osTicket is located at http://127.0.0.1/support/, then the "upload" folder refers to the "support" directory. Also here is an example of how to query for a specific user by email using PHP:

<?php

// API endpoint
$url = 'http://127.0.0.1/support/ost_wbs';

// API key
$apiKey = 'Whatever the api key is';

// Data to be sent in the request
$data = [
    'query' => 'user',
    'condition' => 'specific',
    'sort' => 'email',
    'parameters' => [
        'email' => '[email protected]'
    ]
];

$jsonData = json_encode($data);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'apikey: ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($ch);

if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    die('cURL error: ' . $error);
}

curl_close($ch);

echo 'Response: ' . $response;

This example seems to work great, other than I'm getting a 301 error - any guesses why? I seem to be hitting my endpoint correctly.

I don't recommend using this GitHub repo anymore as it was written for osticket 1.17.

OsTicket is now on version 1.18 which most likely made some changes to the API which is causing these issues. I don't use OsTicket anymore so I cannot help you with this issue.

Appreciate the quick response!

HeartlandCyber avatar Feb 05 '25 22:02 HeartlandCyber