banner

Order Insert Api

URL


https://dispatch.questtag.com/Orders

Method


POST

Authentication


The api is secured with HTTP Basic authentication. While making the request, you need to send 'Basic {API_KEY}:{API_SECRET}' in the Authorization header.

Data Param


The following parameters are mandatory to insert an order. You need to send each of them with correct data type.


Field Name Data Type Example
orderNumber numeric 2224
customerName String Qt Customer
customerAddress String 8400 London Place Washington
customerEmail String qtcustomer@yahoo.com
customerPhoneNumber String +1222222
restaurantName String KFC
restaurantAddress String 8400 London Place Washington

Apart from these required field, you can also send the following optional field in your data param to track different status of your order (i.e. total cost, order item etc)


Field Name Data Type Example
orderItem String
[
    {
        "name":"burger",
        "unitPrice":33,
        "quantity":2,
        "addOns": ["cheese","sauce"],
        "detail": "Last time too much sauce"
    },
    {
        "name":"pizza",
        "unitPrice":50,
        "quantity":2
    }
]
restaurantPhoneNumber String +22345
expectedDeliveryDate Date(yyyy-MM-dd) 2017-06-13
expectedPickupTime Time(HH:mm:ss) 17:45:00
expectedDeliveryTime Time(HH:mm:ss) 17:45:00
orderSource String Seamless
deliveryFee numeric 5.5
tips numeric 2
discountAmount numeric 3.3
tax numeric 4
totalOrderCost numeric 46
clientRestaurantId numeric 12
deliveryInstruction String knock knock
paymentMethod String ‘cash’ or ‘credit card’
creditCardType String ‘visa’, ‘master card’, ‘AMEX’, ’other’
creditCardId numeric (last 4 digit) 1234

While constructing the data params for this api request, remember the following details :-

  • Date and time should be in GMT and time should be in 24 hour format
  • Order items are json string. The three fields(name,quantity,unitPrice) are mandatory. (detail,addOns) field is optional. `addOns` field is an json array of strings.
  • If a field is empty don’t include it in the request.(see the comment in php example)

Success Response


Status : 201 Created

Body :


{
    "success": true,
    "orderId": 118
}

Error Response


Unauthorized

Status : 401 Unauthorized

Body :


{
    "success": false,
    "response": "Authentication failed"
}

Missing Required Params

Status : 400 Bad Request

Body :


{
    "success": false,
    "response": "Required parameter not found"
}

Wrong Param Value

Status : 400 Bad Request

Body :


{
    "success": false,
    "response": "restaurant address must be valid"
}

Server Error

Status : 500 Internal Server Error

Body :


{
    "success": false,
    "response": "Error in inserting order."
}

Sample Call


Example in JavaScript

    var data = new FormData();
    data.append("orderNumber", "9998");
    data.append("customerName", "Mr. Jhon");
    data.append("customerAddress", "8400 London Place, Washington");
    data.append("customerEmail", "jhon@yahoo.com");
    data.append("customerPhoneNumber", "+12242423");
    data.append("restaurantName", "KFC");
    data.append("restaurantAddress", "8400 London Place, Washington");
    data.append("clientRestaurantId", "55");

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === this.DONE) {
        console.log(this.responseText);
      }
    });

    xhr.open("POST", "https://dispatch.questtag.com/Orders");
    xhr.setRequestHeader("authorization", "Basic XXXXXXXXXXXXXXXXX");
    xhr.send(data);

Example in php

    $url = 'https://dispatch.questtag.com/Orders';
    $username = 'xxxxxxx';
    $password = 'xxxxxx';
    $data = array(
        'orderNumber' => 999,
        'customerName' => 'Mr. Jhon',
        'customerAddress' => '8400, London Place Washington',
        'customerEmail' => 'jhon@gmail.com',
        'customerPhoneNumber' => 1222222,
        'restaurantName' => 'KFC',
        'restaurantAddress' => '8400, London Place Washington',
        'clientRestaurantId' => '55'
        //Don’t put  'clientRestaurantId' => ' ');
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    /**
     *To trigger curl error on http error. Set
     *curl_setopt($curl, CURLOPT_FAILONERROR, true);
     *But the following way is preferable as it will let you see the cause of the error.
     */

    $jsonResult = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    $result = json_decode($jsonResult);
    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        if ($result->success) {
            echo $result->orderId;
        } else {
            echo $result->response;
        }
    }

Order Delete Api

URL


https://dispatch.questtag.com/Orders/:order_id

Method


DELETE

Authentication


The api is secured with HTTP Basic authentication. While making the request, you need to send 'Basic {API_KEY}:{API_SECRET}' in the Authorization header.

Success Response


Status : 200 OK

Body :


{
    "success": true,
    "response": "order deleted"
}

Error Response


Unauthorized

Status : 401 Unauthorized

Body :


{
    "success": false,
    "response": "Auth failed"
}

Forbidden

Status : 403 Forbidden

Body :


{
    "success": false,
    "response": "You are not authorized to do this action"
}

Order Not Found

Status : 200 OK

Body :


{
    "success": false,
    "response": "order not found"
}

Sample Call


Example in JavaScript

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
        if (this.readyState === this.DONE) {
            console.log(this.responseText);
        }
    });

    xhr.open("DELETE", "https://dispatch.questtag.com/Orders/122");
    xhr.setRequestHeader("authorization", "Basic XXXXXXXXXXXXXXXXXXXX");
    xhr.send();

Example in php

    $orderId = 129;
    $url = 'https://dispatch.questtag.com/Orders/' . $orderId;
    $username = 'XXXXXXX';
    $password = 'XXXXXXX';

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


    /**
     *To trigger curl error on http error. Set
     *curl_setopt($curl, CURLOPT_FAILONERROR, true);
     *But the following way is preferable as it will let you see the cause of the error.
     */
    $jsonResult = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);
    $result = json_decode($jsonResult);
    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        if ($result->success) {
            echo $result->orderId;
        } else {
            echo $result->response;
        }
    }

Carrier Details Api

URL


https://dispatch.questtag.com/Carrier/Profile/:carrier_id

Method


GET

Authentication


The api is secured with HTTP Basic authentication. While making the request, you need to send 'Basic {API_KEY}:{API_SECRET}' in the Authorization header.

Success Response


Status : 200 OK

Body :


{
    "success": true,
    "carrier": {
        "id": 8,
        "name": "Test Puddin'",
        "personalId": null,
        "codeName": "",
        "phoneNumber": "7575094476",
        "companyId": 4,
        "areaId": 4,
        "areaName": "Fremont, CA, United States",
        "email": "clawrence@aumail.averett.edu",
        "imagePath": null,
        "thumbnailImagePath": null,
        "vehicle": {
            "id": 1,
            "type": "CAR",
            "model": "",
            "description": "",
            "plate": null
        }
    }
}

Error Response


Unauthorized

Status : 401 Unauthorized

Body :


{
    "success": false,
    "response": "Auth failed"
}

Forbidden

Status : 403 Forbidden

Body :


{
    "success": false,
    "response": "You are not authorized to do this action"
}

Carrier Not Found

Status : 200 OK

Body :


{
    "success": false,
    "response": "There is no carrier of this id "
}