CRUD-вебхуки нарядов

В случае CRUD-вебхуков любое изменение в наряде может приводит к отправке вебхука.

CRUD-вебхуки уведовляют обо всех изменениях в наряде, включая обновления состояния. В том числе вы можете определять обновление состояния (поле status) с помощью вебхука job_updated («Наряд обновлен»), сравнивая текущее состояние наряда с предыдущим (оно доступно в поле previous, см. пример ниже). Таким образом, CRUD-вебхуки полностью покрывают функциональность вебхуков изменения состояния.

Ниже приведены примеры тела вебхука для разных типов событий.

Наряд добавлен

{
  "event_type": "job_created",
  "context": {
    "source": "web",
    "happened_at": "2015-01-19T21:02:04.617Z",
    "created_at": "2015-01-19T21:02:04.617Z",
    "user_uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
    "user_email": "jack@black",
    "device_uuid": null
  },
  "job": {
    "uuid": "cb4b2ede-114f-4c55-9118-0b62f8182403"
    "external_id": null,
    "external_order_id": null,
    "serial_no": 22461,
    "status": "started",
    "scheduled_at": "2015-01-19T20:00:00.000Z",
    "scheduled_duration": {
      "minutes": 60
    },
    "template": {
      "uuid": "2bb9f66f-082c-4bfd-b806-e777d483c769",
      "name": "Diagnostic"
    },
    "client": {
      "uuid": "50c773b3-a4f8-5619-be47-cb6a0edb22cc",
      "external_id": "423430387320568-acme"
    },
    "site": {
      "uuid": "dc62cfdf-f9f1-59ec-80bd-ff5da151e515",
      "external_id": "kelheimer-6"
    },
    "type": {
      "uuid": "8d5f2415-fce3-45a6-b417-ad939a63f70d",
      "code": "Diagnostic"
    },
    "timestamps": {
      "en_route_at": "2015-01-19T20:35:04.617Z",
      "started_at": "2015-01-19T21:02:04.617Z",
      "suspended_at": null,
      "finished_at": null,
    },
    "assignee": {
      "worker": {
        "uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
        "email": "john@doe"
      }
    },
    "skills": [
      {
        "uuid": "a1620b1d-257d-49a9-9adf-6e958603c571",
        "name": "Installation"
      },
      {
        "uuid": "ea2af535-33e6-4398-bf37-0fc3f1d0c7a2",
        "name": "Diagnostic"
      }
    ],
    "territory": {
      "uuid": "70f19e99-d3e3-4366-8bd9-2f1c8c8c784a",
      "name": "New York"
    },
    "description": null,
    "address": {
      "formatted": "Kelheimer Str. 6, 10777 Berlin, Germany",
      "entrance_no": null,
      "apartment": null,
      "floor": "3",
      "description": null,
      "geolocation": {
        "longitude": 13.3363265,
        "latitude": 52.4984896
      }
    },
    "contacts": [
      {
        "name": "Herr Karl",
        "value": "0179-1234567",
        "type": "phone"
      }
    ],
    "possible_resolutions": [
      {
        "uuid": "f74c80bd-e21c-4d11-a036-84126004088b",
        "name": "Success",
        "successful": true
      },
      {
        "uuid": "19b30c02-371f-4da7-a24f-cf0dd840b793",
        "name": "Failure",
        "successful": false
      }
    ],
    "custom_fields": [],
    "report_fields": [],
    "version": 1
  }
}

Наряд обновлен

{
  "event_type": "job_updated",
  "context": {
    "source": "mobile",
    "happened_at": "2015-01-20T21:02:04.617Z",
    "created_at": "2015-01-20T21:02:04.617Z",
    "user_uuid": "21a393eb-ff94-4221-b20f-d037d9d658e8",
    "user_email": "john@doe",
    "device_uuid": "75e31d97-dff4-4321-92fe-bc093dc91b51"
  },
  "job": {
    "uuid": "cb4b2ede-114f-4c55-9118-0b62f8182403"
    "external_id": null,
    "external_order_id": null,
    "serial_no": 22461,
    "status": "started",
    "scheduled_at": "2015-01-19T20:00:00.000Z",
    "scheduled_duration": {
      "minutes": 60
    },
    "template": {
      "uuid": "2bb9f66f-082c-4bfd-b806-e777d483c769",
      "name": "Diagnostic"
    },
    "client": {
      "uuid": "50c773b3-a4f8-5619-be47-cb6a0edb22cc",
      "external_id": "423430387320568-acme"
    },
    "site": {
      "uuid": "dc62cfdf-f9f1-59ec-80bd-ff5da151e515",
      "external_id": "kelheimer-6"
    },
    "type": {
      "uuid": "8d5f2415-fce3-45a6-b417-ad939a63f70d",
      "code": "Diagnostic"
    },
    "timestamps": {
      "en_route_at": "2015-01-19T20:35:04.617Z",
      "started_at": "2015-01-19T21:02:04.617Z",
      "suspended_at": null,
      "finished_at": null,
    },
    "assignee": {
      "worker": {
        "uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
        "email": "john@doe"
      }
    },
    "skills": [
      {
        "uuid": "a1620b1d-257d-49a9-9adf-6e958603c571",
        "name": "Installation"
      },
      {
        "uuid": "ea2af535-33e6-4398-bf37-0fc3f1d0c7a2",
        "name": "Diagnostic"
      }
    ],
    "territory": {
      "uuid": "70f19e99-d3e3-4366-8bd9-2f1c8c8c784a",
      "name": "New York"
    },
    "description": null,
    "address": {
      "formatted": "Kelheimer Str. 6, 10777 Berlin, Germany",
      "entrance_no": null,
      "apartment": null,
      "floor": "3",
      "description": null,
      "geolocation": {
        "longitude": 13.3363265,
        "latitude": 52.4984896
      }
    },
    "contacts": [
      {
        "name": "Herr Karl",
        "value": "0179-1234567",
        "type": "phone"
      }
    ],
    "possible_resolutions": [
      {
        "uuid": "f74c80bd-e21c-4d11-a036-84126004088b",
        "name": "Success",
        "successful": true
      },
      {
        "uuid": "19b30c02-371f-4da7-a24f-cf0dd840b793",
        "name": "Failure",
        "successful": false
      }
    ],
    "custom_fields": [],
    "report_fields": [],
    "version": 5,
    "previous": {
      "external_id": null,
      "external_order_id": null,
      "serial_no": 22461,
      "status": "en_route",
      "scheduled_at": "2015-01-19T20:00:00.000Z",
      "scheduled_duration": {
        "minutes": 60
      },
      "template": {
        "uuid": "2bb9f66f-082c-4bfd-b806-e777d483c769",
        "name": "Diagnostic"
      },
      "client": {
        "uuid": "50c773b3-a4f8-5619-be47-cb6a0edb22cc",
        "external_id": "423430387320568-acme"
      },
      "site": {
        "uuid": "dc62cfdf-f9f1-59ec-80bd-ff5da151e515",
        "external_id": "kelheimer-6"
      },
      "type": {
        "uuid": "8d5f2415-fce3-45a6-b417-ad939a63f70d",
        "code": "Diagnostic"
      },
      "timestamps": {
        "en_route_at": "2015-01-19T20:35:04.617Z",
        "started_at": null,
        "suspended_at": null,
        "finished_at": null,
      },
      "assignee": {
        "worker": {
          "uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
          "email": "john@doe"
        }
      },
      "skills": [
        {
          "uuid": "a1620b1d-257d-49a9-9adf-6e958603c571",
          "name": "Installation"
        },
        {
          "uuid": "ea2af535-33e6-4398-bf37-0fc3f1d0c7a2",
          "name": "Diagnostic"
        }
      ],
      "territory": {
        "uuid": "70f19e99-d3e3-4366-8bd9-2f1c8c8c784a",
        "name": "New York"
      },
      "description": null,
      "address": {
        "formatted": "Kelheimer Str. 6, 10777 Berlin, Germany",
        "entrance_no": null,
        "apartment": null,
        "floor": "3",
        "description": null,
        "geolocation": {
          "longitude": 13.3363265,
          "latitude": 52.4984896
        }
      },
      "contacts": [
        {
          "name": "Herr Karl",
          "value": "0179-1234567",
          "type": "phone"
        }
      ],
      "possible_resolutions": [
        {
          "uuid": "f74c80bd-e21c-4d11-a036-84126004088b",
          "name": "Success",
          "successful": true
        },
        {
          "uuid": "19b30c02-371f-4da7-a24f-cf0dd840b793",
          "name": "Failure",
          "successful": false
        }
      ],
      "custom_fields": [],
      "report_fields": [],
      "version": 4
    }
  }
}

Наряд удален

{
  "event_type": "job_removed",
  "context": {
    "source": "web",
    "happened_at": "2015-01-21T21:02:04.617Z",
    "created_at": "2015-01-21T21:02:04.617Z",
    "user_uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
    "user_email": "jack@black",
    "device_uuid": null
  },
  "job": {
    "uuid": "cb4b2ede-114f-4c55-9118-0b62f8182403"
    "external_id": null,
    "external_order_id": null,
    "serial_no": 22461,
    "status": "finished",
    "scheduled_at": "2015-01-19T20:00:00.000Z",
    "scheduled_duration": {
      "minutes": 60
    },
    "template": {
      "uuid": "2bb9f66f-082c-4bfd-b806-e777d483c769",
      "name": "Diagnostic"
    },
    "client": {
      "uuid": "50c773b3-a4f8-5619-be47-cb6a0edb22cc",
      "external_id": "423430387320568-acme"
    },
    "site": {
      "uuid": "dc62cfdf-f9f1-59ec-80bd-ff5da151e515",
      "external_id": "kelheimer-6"
    },
    "type": {
      "uuid": "8d5f2415-fce3-45a6-b417-ad939a63f70d",
      "code": "Diagnostic"
    },
    "timestamps": {
      "en_route_at": "2015-01-19T20:35:04.617Z",
      "started_at": "2015-01-19T21:02:04.617Z",
      "suspended_at": null,
      "finished_at": "2015-01-19T22:35:04.617Z",
    },
    "assignee": {
      "worker": {
        "uuid": "8ebd12cc-b2d9-407c-a4f4-5943263d54a4",
        "email": "john@doe"
      }
    },
    "skills": [
      {
        "uuid": "a1620b1d-257d-49a9-9adf-6e958603c571",
        "name": "Installation"
      },
      {
        "uuid": "ea2af535-33e6-4398-bf37-0fc3f1d0c7a2",
        "name": "Diagnostic"
      }
    ],
    "territory": {
      "uuid": "70f19e99-d3e3-4366-8bd9-2f1c8c8c784a",
      "name": "New York"
    },
    "description": null,
    "address": {
      "formatted": "Kelheimer Str. 6, 10777 Berlin, Germany",
      "entrance_no": null,
      "apartment": null,
      "floor": "3",
      "description": null,
      "geolocation": {
        "longitude": 13.3363265,
        "latitude": 52.4984896
      }
    },
    "contacts": [
      {
        "name": "Herr Karl",
        "value": "0179-1234567",
        "type": "phone"
      }
    ],
    "possible_resolutions": [
      {
        "uuid": "f74c80bd-e21c-4d11-a036-84126004088b",
        "name": "Success",
        "successful": true
      },
      {
        "uuid": "19b30c02-371f-4da7-a24f-cf0dd840b793",
        "name": "Failure",
        "successful": false
      },
      }
    ],
    "custom_fields": [],
    "report_fields": [],
    "version": 25
  }
}

См. также