Project

General

Profile

API - Schedule Save

API Schedule is used to save the schedule from the PBX

API URL

https://[YOUR-PBX-URL]/api/schedule

The data is transmitted via POST or GET and must be of the form:

Array
(
    [action] => save
    [data] => Array
        (
            [element_type] => project
            [schedule_type] => weekdays
            [schedule_data] => Array
                (
                    [0] => Array
                        (
                            [element_id] => 1
                            [day] => 1
                            [data] => Array
                                (
                                    [0] => Array
                                        (
                                            [start] => 09:00:00
                                            [end] => 18:00:00
                                        )

                                )

                            [break_interval] => 
                            [break_message] => 
                            [welcome_message] => 
                            [ns_welcome_message] => 
                            [closed_message] => 
                            [closed_gosub] => 
                        )

                    [1] => Array
                        (
                            [element_id] => 1
                            [day] => 2
                            [data] => Array
                                (
                                    [0] => Array
                                        (
                                            [start] => 09:00:00
                                            [end] => 17:00:00
                                        )

                                )

                            [break_interval] => 
                            [break_message] => 
                            [welcome_message] => 
                            [ns_welcome_message] => 
                            [closed_message] => 
                            [closed_gosub] => 
                        )

                )

        )

    [api_hash] => 07112231a9c89f5b108af08608a97b07
)

The action parameter must have the value save.
The data parameter must contain:
- element_type with one of the values: project, inbound_route, contact, user, ivr_menu, pbx_queue
- schedule_type with the value weekdays sau custom

Weekdays are transmitted in the form:

$days = array(
                    0 => _('Sunday'),
                    1 => _('Monday'),
                    2 => _('Tuesday'),
                    3 => _('Wednesday'),
                    4 => _('Thursday'),
                    5 => _('Friday'),
                    6 => _('Saturday'),
                );

HTTP Headers:

Content-Type: application/json
Authorization: Bearer <token>

Example of parameter generation:

$params = [
    'action' => 'save',
    'data' => [
        'element_type' => 'project',
        'schedule_type' => 'weekdays',
        'schedule_data' => [
            [
                'element_id' => 1,
                'day' => 1,
                'data' => [
                    [
                        //'id' => 2,
                        //'key' => 1,
                        'start' => '09:00:00',
                        'end' => '18:00:00'
                    ]
                ],
                'break_interval' => '',
                'break_message' => '',
                'welcome_message' => '',
                'ns_welcome_message' => '',
                'closed_message' => '',
                'closed_gosub' => ''
            ],
            [
                'element_id' => 1,
                'day' => 2,
                'data' => [
                    [
                        //'id' => 3,
                        //'key' => 1,
                        'start' => '09:00:00',
                        'end' => '17:00:00'
                    ]
                ],
                'break_interval' => '',
                'break_message' => '',
                'welcome_message' => '',
                'ns_welcome_message' => '',
                'closed_message' => '',
                'closed_gosub' => ''
            ]
        ]
    ]
];

Example hash generation:

$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash

Example of sending data:

$url = 'https://[YOUR-PBX-URL]/api/schedule';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}"));

Data sent JSON

{
  "action": "save",
  "data": {
    "element_type": "project",
    "schedule_type": "weekdays",
    "schedule_data": [
      {
        "element_id": 1,
        "day": 1,
        "data": [
          {
            "start": "09:00:00",
            "end": "18:00:00" 
          }
        ],
        "break_interval": "",
        "break_message": "",
        "welcome_message": "",
        "ns_welcome_message": "",
        "closed_message": "",
        "closed_gosub": "" 
      },
      {
        "element_id": 1,
        "day": 2,
        "data": [
          {
            "start": "09:00:00",
            "end": "17:00:00" 
          }
        ],
        "break_interval": "",
        "break_message": "",
        "welcome_message": "",
        "ns_welcome_message": "",
        "closed_message": "",
        "closed_gosub": "" 
      }
    ]
  },
  "api_hash": "07112231a9c89f5b108af08608a97b07" 
}

Response

In case of success:

{
  "has_error": false,
  "messages": [],
  "results": {
    "saved": 1
  }
}

Or in case of error:

{

    "has_error": true,
    "messages": [
        "Invalid schedule type: xxx" 
    ],
    "results": [ ]

}

Available in other languages: RO