Skip to main content

I'm using the endpoint /api/v1.0/tickets/slas to retrieve SLA information related to tickets; however, it returns a 500 Internal Server Error when the itemcount is 0.

{

    "ItemCount": 0,

    "UserToken": "",

    "RequestDate": "2024-11-27T17:54:54.835596Z",

    "ExecutionTime": 348.4801,

    "StatusCode": 500,

    "Message": "Internal Server Error",

    "ServerName": "tickets-00023I",

    "ProcessId": 4020,

    "Properties": {}

}

payloads = 

{

    "Schema": "All",

    "Filters": /

        {

            "Facet": "createddate",

            "Name": "daterange: 11/27/2024-11/27/2024",

            "Value": "daterange: 11/27/2024-11/27/2024"

        }

    ]

}

headers = 

'content-type': 'application/json',
'accept': 'application/json'

‘authorization’: ‘Bearer’ + key

@HLicea 51023bd misd Thank you for submitting your question to our community! 😄

I have reached out to our Support Team API masters, but in the meantime, ​@jclark ​@MattHenry ​@bclark ​@curtis.bohlmeyer any ideas to share? 


That endpoint is right.

Since different products can have different SLA’s, you likely need to add the “ProductId” header to specify Facilities or Ticketing. Your product ID’s should be listed in Admin > Developer Tools in iiQ.


I'm curious about why everything works smoothly when the ItemCount is greater than 0 without any changes. Also, is it normal that the endpoint returns statuscode:500 when there’s no data?


In my experience, IIQ returns 500s when there’s something malformed or missing about the request. As ​@jclark mentioned, there’s probably a missing payload param.

I have a specific block of code for detecting 500s on POST because sometimes they payload isn’t formatted correctly. Python snippet below.

except requests.exceptions.HTTPError as e:
logging.warning(
f"HTTPError exception for API {method} call to {url} with "
f"payload {iiq_payload} | Message: {e}" # | Response: {response}
)
if e.response.status_code == 502 and timeout < max_timeout:
sleep(timeout)
call_api(
url=url,
method=method,
iiq_payload=iiq_payload,
iiq_headers=iiq_headers,
params=params,
timeout=timeout,
max_timeout=max_timeout,
)
elif (
e.response.status_code == 500
and method.upper() == "POST"
):
# Try to fix payload by converting it to str
iiq_payload = json.dumps(iiq_payload)
call_api(
url=url,
method=method,
iiq_payload=iiq_payload,
iiq_headers=iiq_headers,
params=params,
timeout=timeout,
max_timeout=max_timeout,
)
else:
raise

 


Thank you ​@LCampbell for that additional information! 😄


Thank you for your response! I have implemented the code you suggested to verify the payloads, and it seems to be structured correctly. I also added the ProductID to the header, but I am still running into the same issue. The only scenario in which I have detected this problem is when there is no data to retrieve. Is there any documentation available for this endpoint that I could reference? It would help me ensure that my headers and payloads are set up correctly, as well as confirm that I am using the correct endpoint for my target. Thank you very much!


@HLicea 51023bd misd Our documentation for APIs are still being worked on and developed by our dev team. However, there is a developer section within you platform for specific dev tools. 

 


@Kathryn Carter » I think this is a bug for this endpoint and should be escalated to the engineering team. More info below.

@HLicea 51023bd misd » I think your payload is correct, and I can confirm that it only 500s when the resulting response has zero items. I verified through the website that I didn’t have any tickets created on 11/27/2024.

I can POST to https://wusd-org.incidentiq.com/api/v1.0/tickets and pull results with (reverse engineered from HTTP calls on the website)

{
"Schema": "All",
"Filters":
{
"Facet": "createddate",
"FacetName": null,
"Id": null,
"Name": "daterange:11/27/2024-11/27/2024",
"Negative": false,
"Selected": true,
"Value": "daterange:11/27/2024-11/27/2024",
"GroupIndex": 0
}
]
}

But if I POST to https://wusd-org.incidentiq.com/api/v1.0/tickets/slas?$s1000 I get an HTTP 500. If I try to GET, it returns a HTTP 405 “method not allowed”, so this endpoint is expecting a POST with a payload.

If I use the following and POST to https://wusd-org.incidentiq.com/api/v1.0/tickets/slas?$s=1000 I get an HTTP 200 and 27 results

{
"Schema": "All",
"Filters": ,
{
"Facet": "createddate",
"FacetName": null,
"Id": null,
"Name": "daterange:12/03/2024-12/03/2024",
"Negative": false,
"Selected": true,
"Value": "daterange:12/03/2024-12/03/2024",
"GroupIndex": 0
}
]
}

So, what are next steps?

The way I see it, you can either handle the exception when you get a 500 when calling that API, or you can call https://wusd-org.incidentiq.com/api/v1.0/tickets with your filter to get the date range you want, and then run a for loop similar to

for id in ticket_ids:
url = f"{base_url}/tickets/{id}/slas"
iiq_headers = {
"Content-Type": "application/json",
"Authorization": bearer_token,
}
response = requests.get(
url,
headers=iiq_headers
)
# Do something with response

 


@LCampbell I would suggest submitting a ticket to our Support Team then. Make sure to include this link with your ticket so our team has reference to this thread. 

 


@LCampbell I would suggest submitting a ticket to our Support Team then. Make sure to include this link with your ticket so our team has reference to this thread. 

 

Ticket created!


​Thanks so much for your response ​@LCampbell and ​@Kathryn Carter. I’ll work on my code to handle this error; I hope we can have a solution from the engineering team. I appreciate your support!


Reply