Create a new Ticket

Creating a new ticket is a bit more of a complicated process than getting information about tickets. It mainly requires more preparation beforehand. But don't worry, everything that you need is described below.

πŸ“˜

Examples below

The examples below are written in Python and are using requests library for communication with the API. The response from the API will be represented as JSON.

The examples below were tested and they do work, so you can easily follow along.

🚧

API Keys

The API keys used in the examples below are random, and they do not work - use your own API keys.

First steps

Here is the Create a Ticket endpoint that will show you in great detail which fields are required, which fields are optional, and will let you try the endpoint out.

When creating a ticket, you need to have a company set up first. This can be done by going to Settings > Company then clicking on the Edit button in the lower right corner.

Getting the required data

Other than the company data, the creation of a ticket requires providing some information, some of them are IDs of different elements which can be a bit tricky to obtain. Here is the explanation of how to get the required IDs.

A ticket type is a required field for creating a new ticket. If you do not have the ticket type created, you have to do that first. The ticket type page on the platform can be found by going to Settings > Company, clicking on the Edit button in the lower right corner, and selecting the Tickets tab. The Ticket Types will be placed next to the Ticket Categories in the second tab-bar. Here, you will see your already created ticket types, but you will also be able to create new ones.

But how to get the ID?

The ID of a particular ticket type can be found by calling the Get Ticket Types endpoint and filtering the data out to get only a specific type.

The other fields, that also require the ID, are optional for creating a ticket. This means that they do not have to be provided with the request. Those are the following fields:

  • property
  • container
  • assignee
  • requested_by

If you want to supply the request with the information of those elements, the best way to obtain their IDs is to call their respective endpoints, get all the elements and then filter them to get only the specific one - the same approach as with getting the ticket type ID.

Here are the endpoints to call to get all the data of the above elements:

property = "https://platform-api.wastehero.io/api/v3/property/"
container = "https://platform-api.wastehero.io/api/v3/container/"
assignee = "https://platform-api.wastehero.io/api/v3/user/"
requested_by = "https://platform-api.wastehero.io/api/v3/property_user/"

Another optional (and slightly tricky) field is location, which takes a location object as a parameter. location should look like this:

location = {
    "longitude": "10.203921",
    "latitude": "56.092592",
    "name": ""
}

Building the request body

If you went through the section above, and have all the data, you are ready to create a ticket. The majority of the fields that are meant to be sent with the body are optional, so if you are not sure what has to be sent, refer to the API reference.

In general, the body for the request could look like the one presented below.

body = {
  "ticket_type": "gDuatLM4i4df/MOkXQSaHg==",
  "property": "ZpHUiuj5GoPfHI6lGgRmQg==",
  "location": {
    "longitude": "10.203921",
    "latitude": "56.092592",
    "name": ""
  },
  "container": "eo6jLvV82mGGTErfCBhsng==",
  "assignee": "01jQ9TYpxlbH0CLeHFetHA==",
  "requested_by": "4ft7D+oX7mHPFHDiJEcMhw==",
  "status": 1,
  "priority": 2,
  "description": "This is my new ticket",
  "time_spent": "",
  "waste_weight_estimate": "",
  "waste_volume_estimate": "",
  "deadline": "",
  "requested_by_other": "",
  "preferred_date": "",
  "ignore_service_fee": False
}

What is worth mentioning is that the status and priority fields must have a particular value assigned to them (provided as an integer). The fields have the following options available:

  • For status

    • 1 (Created)
    • 2 (Open)
    • 3 (Pending)
    • 4 (On hold)
    • 5 (In progress)
    • 6 (Completed)
    • 7 (Rejected)
  • For priority

    • 0 (None)
    • 1 (Low)
    • 2 (Medium)
    • 3 (High)
    • 4 (Critical)

Final example

Now that you know how to create a body, it is time to put everything together into a final request. Below, you can see what such an example could look like.

Note that because we want to create a new ticket, we are going to use the POST request, and not GET as in previous ticket endpoints.

import requests
import json

url = "https://platform-api.wastehero.io/api/v3/ticket/"

headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "X-API-Key": "60eea422-7091-46d3-9117-3408af60d9bd"
}

body = {
  "ticket_type": "gDuatLM4i4df/MOkXQSaHg==",
  "property": "ZpHUiuj5GoPfHI6lGgRmQg==",
  "location": {
    "longitude": "10.203921",
    "latitude": "56.092592",
    "name": ""
  },
  "container": "eo6jLvV82mGGTErfCBhsng==",
  "assignee": "01jQ9TYpxlbH0CLeHFetHA==",
  "requested_by": "4ft7D+oX7mHPFHDiJEcMhw==",
  "status": 1,
  "priority": 2,
  "description": "This is my new ticket",
  "time_spent": "",
  "waste_weight_estimate": "",
  "waste_volume_estimate": "",
  "deadline": "",
  "requested_by_other": "",
  "preferred_date": "",
  "ignore_service_fee": False
}

response = requests.get(url, data=json.dumps(body), headers=headers, )

print(response.text)

Response models

After you make a request to the correct endpoint for creating a new ticket - if everything went correctly - you are going to get back a payload with all the information of the newly created ticket. Below you can see what such a payload will look like.

{
  "ticket_type": {
    "id": "string",
    "name": "string",
    "service_type": "string"
  },
  "property": {
    "location": {
      "longitude": 0,
      "latitude": 0,
      "name": "string"
    },
    "unique_number": "string",
    "note": "string",
    "meta_data": {},
    "created_at": "2022-08-31T14:00:47.715Z"
  },
  "location": {
    "longitude": 0,
    "latitude": 0,
    "name": "string"
  },
  "container": {
    "container_type": {
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "pickup_setting": {
        "id": "string",
        "project": {
          "id": "string",
          "name": "string",
          "description": "string",
          "creating_demo_data": false
        },
        "name": "string",
        "pickup_method": "string",
        "container_status": "string",
        "emptying_interval_from": "string",
        "emptying_interval_to": "string",
        "exclude_days": [
          "string"
        ],
        "fixed_pickups_period": "string",
        "pickup_interval": "string",
        "pickup_repeat_period": 0,
        "allowed_hours_from": "string",
        "allowed_hours_to": "string",
        "amount_days_between_pickups": 0,
        "minimum_days_between_pickup": 0,
        "collection_per_week": 0,
        "first_collection": "2022-08-31"
      },
      "name": "string",
      "emplacement": "string",
      "mobility": "string",
      "vehicle_coupling": [
        "string"
      ],
      "container_access": "string",
      "emptying_time": 0,
      "width": 0,
      "height": 0,
      "length": 0,
      "diameter": 0,
      "is_cylindrical": false
    },
    "container_group": {
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "location": {
        "longitude": 0,
        "latitude": 0,
        "name": "string"
      },
      "created_at": true,
      "name": "string",
      "updated_at": "string"
    },
    "stored_at_depot": {
      "id": "string",
      "location": {
        "longitude": 0,
        "latitude": 0,
        "name": "string"
      },
      "name": "string",
      "description": "string",
      "geofence_radius": 0,
      "opening_time": "string",
      "closing_time": "string",
      "time_to_unload_truck": "string",
      "time_to_leave_the_facility": "string",
      "amount_of_trucks": 0,
      "capacity_of_trucks": 0,
      "workshop_service_description": "string",
      "workshop_type": "string"
    },
    "location": {
      "longitude": 0,
      "latitude": 0,
      "name": "string"
    },
    "waste_fraction": {
      "id": "string",
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "name": "string",
      "waste_type": "string",
      "waste_category": "string",
      "waste_substance": "string",
      "weight_factor": 0
    },
    "project": {
      "id": "string",
      "name": "string",
      "description": "string",
      "creating_demo_data": false
    },
    "measurement": {
      "fill_level_measurement_meta": {
        "created_at": "2022-08-31T14:00:47.715Z",
        "protocol": "string",
        "json_version": 0,
        "transmit_count": 0,
        "gwt": "",
        "battery_level": 0,
        "rsi": 0,
        "register_time": 0,
        "snr": 0,
        "header_version": 0,
        "text": "string",
        "ccid": "string",
        "crc": "string",
        "act": "string",
        "oper": "string",
        "ch": 0,
        "cid": "string",
        "lac": "string",
        "ant": "string",
        "old_status_code": 0,
        "battery_percentage": 0
      },
      "fill_level": 0,
      "raw_measurements": [
        0
      ],
      "fill_percentage": 0,
      "temperature": 0,
      "dev_id": "",
      "created_at": "2022-08-31T14:00:47.715Z"
    },
    "container_id": "string",
    "status": "string",
    "allowed_hours_start": "string",
    "allowed_hours_end": "string",
    "description": "string",
    "show_on_route": false,
    "pickup_method": "string",
    "sensor_fill_level": 0,
    "prioritize_in_start_of_route": false,
    "updated_at": "2022-08-31T14:00:47.715Z",
    "created_at": "2022-08-31T14:00:47.715Z"
  },
  "assignee": {
    "id": "string",
    "active_token": "string",
    "external_crm_id": "string",
    "phone_number": "string",
    "language": "string",
    "is_sms": false,
    "is_email": false,
    "is_push": true,
    "created_at": "2022-08-31T14:00:47.715Z",
    "updated_at": "2022-08-31T14:00:47.715Z",
    "demo_expire_date": "2022-08-31",
    "is_superuser": false,
    "is_demo": false,
    "is_reseller": false,
    "is_master": false,
    "is_beta": false,
    "active_projects": [
      0
    ]
  },
  "requested_by": {
    "anonymous": false,
    "token": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "name": "string",
    "email": "string",
    "phone_number": "string",
    "phone_number_token": "string",
    "language": "string",
    "created_at": "2022-08-31T14:00:47.715Z"
  },
  "status": 0,
  "priority": 0,
  "description": "string",
  "migrated_from_id": "string",
  "time_spent": 0,
  "waste_weight_estimate": 0,
  "waste_volume_estimate": 0,
  "deadline": "2022-08-31T14:00:47.715Z",
  "requested_by_other": "string",
  "preferred_date": "2022-08-31",
  "ignore_service_fee": false,
  "id": "string",
  "created_at": "2022-08-31T14:00:47.715Z",
  "updated_at": "2022-08-31T14:00:47.715Z",
  "reporter": {
    "id": "string",
    "active_token": "string",
    "external_crm_id": "string",
    "phone_number": "string",
    "language": "string",
    "is_sms": false,
    "is_email": false,
    "is_push": true,
    "created_at": "2022-08-31T14:00:47.715Z",
    "updated_at": "2022-08-31T14:00:47.715Z",
    "demo_expire_date": "2022-08-31",
    "is_superuser": false,
    "is_demo": false,
    "is_reseller": false,
    "is_master": false,
    "is_beta": false,
    "active_projects": [
      0
    ]
  },
  "status_open_at": "2022-08-31T14:00:47.715Z",
  "status_pending_at": "2022-08-31T14:00:47.715Z",
  "status_on_hold_at": "2022-08-31T14:00:47.715Z",
  "status_in_progress_at": "2022-08-31T14:00:47.715Z",
  "status_completed_at": "2022-08-31T14:00:47.715Z",
  "status_rejected_at": "2022-08-31T14:00:47.715Z",
  "container_price": {
    "id": "string",
    "pickup_setting": {
      "id": "string",
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "name": "string",
      "pickup_method": "string",
      "container_status": "string",
      "emptying_interval_from": "string",
      "emptying_interval_to": "string",
      "exclude_days": [
        "string"
      ],
      "fixed_pickups_period": "string",
      "pickup_interval": "string",
      "pickup_repeat_period": 0,
      "allowed_hours_from": "string",
      "allowed_hours_to": "string",
      "amount_days_between_pickups": 0,
      "minimum_days_between_pickup": 0,
      "collection_per_week": 0,
      "first_collection": "2022-08-31"
    },
    "waste_fraction": {
      "id": "string",
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "name": "string",
      "waste_type": "string",
      "waste_category": "string",
      "waste_substance": "string",
      "weight_factor": 0
    },
    "container_type": {
      "project": {
        "id": "string",
        "name": "string",
        "description": "string",
        "creating_demo_data": false
      },
      "pickup_setting": {
        "id": "string",
        "project": {
          "id": "string",
          "name": "string",
          "description": "string",
          "creating_demo_data": false
        },
        "name": "string",
        "pickup_method": "string",
        "container_status": "string",
        "emptying_interval_from": "string",
        "emptying_interval_to": "string",
        "exclude_days": [
          "string"
        ],
        "fixed_pickups_period": "string",
        "pickup_interval": "string",
        "pickup_repeat_period": 0,
        "allowed_hours_from": "string",
        "allowed_hours_to": "string",
        "amount_days_between_pickups": 0,
        "minimum_days_between_pickup": 0,
        "collection_per_week": 0,
        "first_collection": "2022-08-31"
      },
      "name": "string",
      "emplacement": "string",
      "mobility": "string",
      "vehicle_coupling": [
        "string"
      ],
      "container_access": "string",
      "emptying_time": 0,
      "width": 0,
      "height": 0,
      "length": 0,
      "diameter": 0,
      "is_cylindrical": false
    },
    "name": "string",
    "invoice_name": "string",
    "amount": 0,
    "start_date": "2022-08-31",
    "end_date": "2022-08-31",
    "recurring_interval": 12,
    "created_at": "2022-08-31T14:00:47.715Z"
  }
}

If the request was not successful, it will result in the 400 response code, which signifies an error. This response will also come with its own payload - showing what went wrong and explaining why.

If you get the 400 response code back, the new ticket was not created, and you have to fix the mistake and send a request one more time.

{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}