Skip to main content

Hi.  Is there an API to find an existing ticket based on its ticket number rather than its GUID?

 

This API requires the GUID: https://incidentiq.stoplight.io/docs/v1/fac7a730d6815-get-a-ticket

@AKennis 77b3f7 ouboces Thank you for submitting your question to our community! 😄

I have reached out to our API support specialist for this. In the meantime, I am tagging our API specialists @curtis.bohlmeyer @bclark @jclark @MattHenry Any thoughts here? 


Hi.  Is there an API to find an existing ticket based on its ticket number rather than its GUID?

 

This API requires the GUID: https://incidentiq.stoplight.io/docs/v1/fac7a730d6815-get-a-ticket

There sortof is… but it isn’t really documented. It isn’t very easy either.

You can post to this endpoint

https://domain.incidentiq.com/api/v1.0/tickets?$s=20&$o=TicketPriority%20DESC

to get ticket listings. Unfortunately, to filter it you have to have the GUID of the ticket still (either by including a filter payload or by adding the GUID alike you described).

 

When filtering on the front end you can filter by ticket # but it is using their internal API to pull that list and still filters with the GUID of each ticket. So that isn’t very helpful.

One option is to use their new omni search which doesn’t appear to be documented for API use… looks like you just do a GET request to 

https://domain.incidentiq.com/api/search/v2/expression?s=8787

You could then parse the JSON response to find item > entityTypeQueryResults > tickets
If “hits” is 1 then just take the first “formattedItems” entry.

If hits is > 1 you can perform a request with each GUID and check the TicketNumber string field on each response.

 

Keep in mind though, the search endpoint isn’t documented so it probably isn’t supported and could change.

 

Good luck! The API is much better than it was when we started; hopefully they can add better filter functionalities to the tickets resource in the future.


This is what I do to search a ticket number via the API

 

ticketInfo=$(curl -s POST 'https://YOURINSTANCE.incidentiq.com/api/v1.0/search' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: en-US,en;q=0.9' \
--header 'SiteId: '$siteId'' \
--header 'productid: '$ticketingProductId'' \
--header 'cache-control: no-cache' \
--header 'client: WebBrowser' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer '$iiqToken'' \
--data '{"Query":"'$ticketNumberHere'"}')

 


This is what I do to search a ticket number via the API

 

ticketInfo=$(curl -s POST 'https://YOURINSTANCE.incidentiq.com/api/v1.0/search' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: en-US,en;q=0.9' \
--header 'SiteId: '$siteId'' \
--header 'productid: '$ticketingProductId'' \
--header 'cache-control: no-cache' \
--header 'client: WebBrowser' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer '$iiqToken'' \
--data '{"Query":"'$ticketNumberHere'"}')

 

Nice I didn’t know about the POST and data payload option. Was that documented somewhere and I missed it?


I want to say it was from a chat with support but I’m not sure to be honest.


@MattHenry I think the with the endpoint that @bclark is using being ....incidentiq.com/api/v1.0/search that payload is the same as doing a global search for a string. I’ve used that in similar fashion to find a user by email address. There’s another key:value pair for the payload “Facets”:{facet_number} that narrows it down to tickets, users or assets… I’d have to do some digging to confirm.


Thanks everyone - I got /api/v1.0/search to work as described.  Here’s my Go code for that:

 

 

type SearchForTicketReq struct {

    IiqApiKey string

    TicketNum string

}

func SearchForTicket(req SearchForTicketReq) (string, error) {

    payload := fmt.Sprintf(`

    {

         "Query": "%s"

    }    

    `, req.TicketNum)

    iiqReq, err := initIiqV1Req(req.IiqApiKey, http.MethodPost, "search", payload)

    if err != nil {

        return "", err

    }

    res, err := http.DefaultClient.Do(iiqReq)

    if err != nil {

        return "", err

    }

    defer res.Body.Close()

    resBody, err := io.ReadAll(res.Body)

    if err != nil {

        return "", err

    }

    if res.StatusCode < 200 || res.StatusCode > 299 {

        return "", fmt.Errorf("/search responded with unexpected status code %d, body %s", res.StatusCode, string(resBody))

    }

    type searchQueryTicket struct {

        TicketId     string

        TicketNumber string

    }

    type searchItemData struct {

        Tickets ]searchQueryTicket

    }

    type searchRespData struct {

        Item searchItemData

    }

    var data searchRespData

    err = json.Unmarshal(resBody, &data)

    if err != nil {

        return "", err

    }

    for _, t := range data.Item.Tickets {

        if t.TicketNumber == req.TicketNum {

            return t.TicketId, nil

        }

    }

    return "", fmt.Errorf("no ticket found with number %s", req.TicketNum)

}

 


Reply