BMSVieira / osticket-api

OSTicket Unofficial API
MIT License
29 stars 11 forks source link

Getting 500 Internal Server Error #21

Open dgomiller opened 6 months ago

dgomiller commented 6 months ago

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":"dang@norco-inc.com" } }

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.

At0kir commented 6 months ago

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' => 'EmailToSearch@gmail.com'
    ]
];

$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;
Jill1995 commented 5 months ago

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);
    }
GENnetuk-DEV commented 4 months ago

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.