File size: 1,364 Bytes
03eca9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?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";
}