| <?php |
|
|
| $u = get_user_by('login', 'admin'); |
| if (!$u) { |
| echo "admin user not found\n"; |
| exit(1); |
| } |
| wp_set_current_user((int) $u->ID); |
|
|
| function call_rest(string $method, string $route, array $params = []): array { |
| $req = new WP_REST_Request($method, $route); |
| foreach ($params as $k => $v) { |
| $req->set_param($k, $v); |
| } |
| $res = rest_do_request($req); |
| $server = rest_get_server(); |
| $data = $server->response_to_data($res, false); |
| return [ |
| 'status' => $res->get_status(), |
| 'data' => $data, |
| ]; |
| } |
|
|
| $statuses = call_rest('GET', '/indo-mvp/v1/statuses'); |
| echo "statuses_status=" . $statuses['status'] . "\n"; |
| echo "statuses_data=" . wp_json_encode($statuses['data']) . "\n"; |
|
|
| $list = call_rest('GET', '/indo-mvp/v1/leads', ['per_page' => 1]); |
| echo "leads_status=" . $list['status'] . "\n"; |
| echo "leads_data=" . wp_json_encode($list['data']) . "\n"; |
|
|
| $id = 0; |
| if (isset($list['data']['items'][0]['id'])) { |
| $id = (int) $list['data']['items'][0]['id']; |
| } |
| if ($id > 0) { |
| $upd = call_rest('POST', '/indo-mvp/v1/leads/' . $id, ['status' => 'contacted', 'admin_note' => 'REST smoke ok']); |
| echo "update_status=" . $upd['status'] . "\n"; |
| echo "update_data=" . wp_json_encode($upd['data']) . "\n"; |
|
|
| $wa = call_rest('GET', '/indo-mvp/v1/leads/' . $id . '/whatsapp'); |
| echo "wa_status=" . $wa['status'] . "\n"; |
| echo "wa_data=" . wp_json_encode($wa['data']) . "\n"; |
| } |
|
|
|
|