Api Reference

Using JSON Web Tokens and OAUTH, we will enable customers to access their ticket information.
API methods will include:

Receive Authorization

Fetch the JWT token with valid login information

URL

ssdinternalproject.azurewebsites.net/oauth/token

Method

POST

Request

Parameters inside the Body with "x-xxx-form-urlencoded" format
parameter type description
username string
password string
grant_type string 'password' was used

Responses

Parameters inside the JSON type
parameter type description
access_token string
token_type string the schema as the header
expires_in number the remained seconds from now

Simple JavaScript Example

window.onload = function() {
    document.getElementById("button").onclick= function() {
        var http = new XMLHttpRequest();
        var url = "http://ssdinternalproject.azurewebsites.net/oauth/token";
        // There are three parameters for this token request
        // 1. username, 
        // 2. password, 
        // 3. and grant_type = "password"
        var params = "username=kimberly@my.bcit.ca&password=P@ssword&grant_type=password";
        http.open("POST", url, true);
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                myObj = JSON.parse(this.responseText);
        // There are three result elements from the response
                generateElement("access_token", myObj.access_token);
                generateElement("token_type", myObj.token_type);
                generateElement("expires_in", myObj.expires_in);
            }
        }
        http.send(params);
    }
}
function generateElement(inputKey, inputSty) {
    var para = document.createElement("li");                              
    para.appendChild(document.createTextNode(inputKey + " -- " + inputSty));                                          
    document.body.appendChild(para);                             
}

Get Ticket by Ticket Id

Fetch the ticket info searched by ticket Id

URL

ssdinternalproject.azurewebsites.net/api/ticket/ticket_id

Method

GET

Request

Parameters inside the Headers
parameter type description
Content-Type string 'application/json' was used
Accept string 'application/json' was used
Authorization string format is 'token_type access_token', and both of them are received form the previous api "oauth/token"

Responses

Parameters inside the JSON type
parameter type description
ticketId number
repairDescription string
creationDate Date
repairStartDate Date
repairFinishDate Date
finishDate Date
notes string
hours number
quotedCost number
finalCost number
statusId number
deviceId number
userTickets list
ticketImages list

Simple JavaScript Example

var r = new XMLHttpRequest()
window.onload = function() {
    document.getElementById("button").onclick= function() {
        var http = new XMLHttpRequest();
        var ticket_id = document.getElementById("ticketID").value;
        // Pass ticket_id inside the GET ticket request
        var url = "http://ssdinternalproject.azurewebsites.net/api/ticket/" + ticket_id;
        http.open("GET", url, true);
        http.setRequestHeader("Content-type", "application/json");
        http.setRequestHeader("Accept", "application/json");
        // The Authorication should be 'token_type + access_token ' received from 'oauth/token' api
        http.setRequestHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1laWQiOiIxMjcyZjc1YS1iMTNhLTRiNGUtOWU5Yy03OGE0NDA5ZTllMDMiLCJ1bmlxdWVfbmFtZSI6ImtpbWJlcmx5QG15LmJjaXQuY2EiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL2FjY2Vzc2NvbnRyb2xzZXJ2aWNlLzIwMTAvMDcvY2xhaW1zL2lkZW50aXR5cHJvdmlkZXIiOiJBU1AuTkVUIElkZW50aXR5IiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiI1MjlmNjAwYy05NjFlLTQ5YTctOGM2YS1iNWY3N2JiZDg5YWIiLCJyb2xlIjoiYWRtaW4iLCJpc3MiOiJodHRwOi8vZnJhbmtjaDUudzExLndoLTIuY29tL3NzZGludGVybmFscHJvamVjdCIsImF1ZCI6IjQxNGUxOTI3YTM4ODRmNjhhYmM3OWY3MjgzODM3ZmQxIiwiZXhwIjoxNDkyNjI0NzA1LCJuYmYiOjE0OTI1MzgzMDV9.gywpfX7rZQUgdVUmvXRwfOdeKLdPEmymUfJSeUrAFL4");
        
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                myObj = JSON.parse(this.responseText);
                var counter = 1;
                for(var key in myObj){
                    document.write("Tidket " + counter);
                    var val = myObj[key];
                    for(var subKey in val){
                        generateElement(subKey, val[subKey]);
                    }
                    counter ++;
                    document.write("<br />");
                }
            }
        }
        http.send();
    }
}
function generateElement(inputKey, inputSty) {
    var para = document.createElement("li");                             
    para.appendChild(document.createTextNode(inputKey + " -- " + inputSty));                                          
    document.body.appendChild(para);                             
}

Get All Tickets by User Id

Fetch all the ticket info searched by user Id

URL

ssdinternalproject.azurewebsites.net/api/tickets/user_id

Method

GET

Request

Parameters inside the Headers
parameter type description
Content-Type string 'application/json' was used
Accept string 'application/json' was used
Authorization string format is 'token_type access_token', and both of them are received form the previous api "oauth/token"

Responses

Parameters inside the JSON type
parameter type description
ticketId number
repairDescription string
creationDate Date
repairStartDate Date
repairFinishDate Date
finishDate Date
notes string
hours number
quotedCost number
finalCost number
statusId number
deviceId number
userTickets list
ticketImages list

Simple JavaScript Example

window.onload = function() {
    document.getElementById("button").onclick= function() {
        var http = new XMLHttpRequest();
        var user_id = document.getElementById("ticketID").value;
        // Pass user_id inside the GET tickets request
        var url = "http://ssdinternalproject.azurewebsites.net/api/tickets/" + user_id;
        http.open("GET", url, true);
        http.setRequestHeader("Content-type", "application/json");
        http.setRequestHeader("Accept", "application/json");
        // The Authorication should be 'token_type + access_token ' received from 'oauth/token' api
        http.setRequestHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1laWQiOiIxMjcyZjc1YS1iMTNhLTRiNGUtOWU5Yy03OGE0NDA5ZTllMDMiLCJ1bmlxdWVfbmFtZSI6ImtpbWJlcmx5QG15LmJjaXQuY2EiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL2FjY2Vzc2NvbnRyb2xzZXJ2aWNlLzIwMTAvMDcvY2xhaW1zL2lkZW50aXR5cHJvdmlkZXIiOiJBU1AuTkVUIElkZW50aXR5IiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiI1MjlmNjAwYy05NjFlLTQ5YTctOGM2YS1iNWY3N2JiZDg5YWIiLCJyb2xlIjoiYWRtaW4iLCJpc3MiOiJodHRwOi8vZnJhbmtjaDUudzExLndoLTIuY29tL3NzZGludGVybmFscHJvamVjdCIsImF1ZCI6IjQxNGUxOTI3YTM4ODRmNjhhYmM3OWY3MjgzODM3ZmQxIiwiZXhwIjoxNDkyNjI0NzA1LCJuYmYiOjE0OTI1MzgzMDV9.gywpfX7rZQUgdVUmvXRwfOdeKLdPEmymUfJSeUrAFL4");
        
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                myObj = JSON.parse(this.responseText);
                var counter = 1;
                for(var key in myObj){
                    document.write("Tidket " + counter);
                    var val = myObj[key];
                    for(var subKey in val){
                        generateElement(subKey, val[subKey]);
                    }
                    counter ++;
                    document.write("<br />");
                }
            }
        }
        http.send();
    }
}
function generateElement(inputKey, inputSty) {
    var para = document.createElement("li");                             
    para.appendChild(document.createTextNode(inputKey + " -- " + inputSty));                                          
    document.body.appendChild(para);                             
}

Get Tickets-Ready For Pickup by User Id

Fetch all the ready-to-pickup ticket info searched by user Id

URL

ssdinternalproject.azurewebsites.net/api/tickets-ready/user_id

Method

GET

Request

Parameters inside the Headers
parameter type description
Content-Type string used 'application/json' was used
Accept string used 'application/json' was used
Authorization string format is 'token_type access_token', and both of them are received form the previous api "oauth/token"

Responses

Parameters inside the JSON type
parameter type description
ticketId number
repairDescription string
creationDate Date
repairStartDate Date
repairFinishDate Date
finishDate Date
notes string
hours number
quotedCost number
finalCost number
statusId number
deviceId number
userTickets list
ticketImages list

Simple JavaScript Example

window.onload = function() {
    document.getElementById("button").onclick= function() {
        var http = new XMLHttpRequest();
        var user_id = document.getElementById("ticketID").value;
        // Pass user_id inside the GET ready-tickets request
        var url = "http://ssdinternalproject.azurewebsites.net/api/tickets-ready/" + user_id;
        http.open("GET", url, true);
        http.setRequestHeader("Content-type", "application/json");
        http.setRequestHeader("Accept", "application/json");
        // The Authorication should be 'token_type + access_token ' received from 'oauth/token' api
        http.setRequestHeader("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1laWQiOiIxMjcyZjc1YS1iMTNhLTRiNGUtOWU5Yy03OGE0NDA5ZTllMDMiLCJ1bmlxdWVfbmFtZSI6ImtpbWJlcmx5QG15LmJjaXQuY2EiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL2FjY2Vzc2NvbnRyb2xzZXJ2aWNlLzIwMTAvMDcvY2xhaW1zL2lkZW50aXR5cHJvdmlkZXIiOiJBU1AuTkVUIElkZW50aXR5IiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiI1MjlmNjAwYy05NjFlLTQ5YTctOGM2YS1iNWY3N2JiZDg5YWIiLCJyb2xlIjoiYWRtaW4iLCJpc3MiOiJodHRwOi8vZnJhbmtjaDUudzExLndoLTIuY29tL3NzZGludGVybmFscHJvamVjdCIsImF1ZCI6IjQxNGUxOTI3YTM4ODRmNjhhYmM3OWY3MjgzODM3ZmQxIiwiZXhwIjoxNDkyNjI0NzA1LCJuYmYiOjE0OTI1MzgzMDV9.gywpfX7rZQUgdVUmvXRwfOdeKLdPEmymUfJSeUrAFL4");
        
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                myObj = JSON.parse(this.responseText);
                var counter = 1;
                for(var key in myObj){
                    document.write("Tidket " + counter);
                    var val = myObj[key];
                    for(var subKey in val){
                        generateElement(subKey, val[subKey]);
                    }
                    counter ++;
                    document.write("<br />");
                }
            }
        }
        http.send();
    }
}
function generateElement(inputKey, inputSty) {
    var para = document.createElement("li");                             
    para.appendChild(document.createTextNode(inputKey + " -- " + inputSty));                                          
    document.body.appendChild(para);                             
}