-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl-rpc.sh
82 lines (72 loc) · 1.65 KB
/
curl-rpc.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /bin/bash
# need jq: apt-get install jq
# Ok, return a dict
_authenticate() {
data="{
\"jsonrpc\": \"2.0\",
\"id\": null,
\"method\": \"call\",
\"params\": {
\"db\": \"$2\",
\"login\": \"$3\",
\"password\": \"$4\"
}
}"
curl -X POST \
-H 'Content-Type: application/json' \
--data $data \
--url "$1/web/session/authenticate" \
-sL
}
authenticate() {
echo $(_authenticate $@ | jq ".result.uid")
}
# OK
common() {
data="{
\"jsonrpc\": \"2.0\",
\"id\": 65663464,
\"method\": \"call\",
\"params\": {
\"service\": \"common\",
\"method\": \"login\",
\"args\": [
\"$2\", \"$3\", \"$4\"
]
}
}"
print $data
curl -X POST \
-H 'Content-Type: application/json' \
--data $data \
--url "$1/jsonrpc" \
-L
}
# Ok, use the uid instead of login
raw_query() {
user_id=$(authenticate $1 $2 $3 $4)
echo $user_id
data="{
\"jsonrpc\": \"2.0\",
\"id\": null,
\"method\": \"call\",
\"params\": {
\"service\": \"object\",
\"method\": \"execute\",
\"args\": [
\"$2\",
$user_id,
\"$4\",
\"res.partner\",
\"search\",
[]
]
}
}"
print $data
curl -X POST \
-H 'Content-Type: application/json' \
--data $data \
--url "$1/jsonrpc" \
-L
}