Skip to content

Commit 730e4ac

Browse files
committed
added make_api.sh
1 parent 8254dfe commit 730e4ac

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

ipaas/make_api.sh

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env bash
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: 2023-06-10 22:44:21 +0100 (Sat, 10 Jun 2023)
6+
#
7+
# https://github.com/HariSekhon/DevOps-Bash-tools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12+
#
13+
# https://www.linkedin.com/in/HariSekhon
14+
#
15+
16+
set -euo pipefail
17+
[ -n "${DEBUG:-}" ] && set -x
18+
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
20+
# shellcheck disable=SC1090,SC1091
21+
. "$srcdir/lib/utils.sh"
22+
23+
# shellcheck disable=SC2034,SC2154
24+
usage_description="
25+
Queries the Make.com API
26+
27+
Automatically handles authentication via environment variable \$MAKE_API_KEY
28+
Must also set the \$MAKE_ZONE eg. 'eu1'
29+
30+
Replaces {organizationId} in the URL with \$MAKE_ORGANIZATION_ID if set, otherwise queries the API and uses the first organization returned by the API
31+
32+
Can specify \$CURL_OPTS for options to pass to curl or provide them as arguments
33+
34+
35+
Set up your API token here:
36+
37+
https://eu1.make.com/user/api
38+
39+
40+
API Reference:
41+
42+
https://www.make.com/en/api-documentation
43+
44+
45+
Examples:
46+
47+
Some of these may not work on the free plan, see this issue:
48+
49+
https://community.make.com/t/erro-403-permission-denied-forbidden-to-use-token-authorization-for-this-organization/9946
50+
51+
52+
Ping the API:
53+
54+
${0##*/} /ping
55+
56+
Get currently authenticated user:
57+
58+
${0##*/} /users/me | jq .
59+
60+
List users / teams / organizations / license:
61+
62+
# 403 - VPN access only
63+
#${0##*/} /admin/users
64+
#${0##*/} /admin/teams
65+
#${0##*/} /admin/organizations
66+
#${0##*/} /admin/system-settings/default-license
67+
68+
List Connections:
69+
70+
${0##*/} /connections?teamId=...
71+
72+
List Data Stores:
73+
74+
${0##*/} /data-stores?teamId=...
75+
76+
List Hooks:
77+
78+
${0##*/} /hooks?teamId=...
79+
80+
List Notifications:
81+
82+
${0##*/} /notifications | jq .
83+
84+
List User's Organizations (shows API limit here):
85+
86+
${0##*/} /organizations | jq .
87+
88+
Get Organization Details:
89+
90+
${0##*/} /organizations/{organizationId}
91+
92+
List Scenarios:
93+
94+
${0##*/} /scenarios?teamId=...
95+
96+
List Teams:
97+
98+
${0##*/} /teams?organizationId={organizationId}
99+
100+
List Templates:
101+
102+
${0##*/} /templates
103+
104+
List Users:
105+
106+
${0##*/} /users?organizationId={organizationId} | jq .
107+
"
108+
109+
# used by usage() in lib/utils.sh
110+
# shellcheck disable=SC2034
111+
usage_args="/path [<curl_options>]"
112+
113+
help_usage "$@"
114+
115+
min_args 1 "$@"
116+
117+
check_env_defined MAKE_API_KEY
118+
check_env_defined MAKE_ZONE
119+
120+
url_base="https://$MAKE_ZONE.make.com/api/v2"
121+
122+
curl_api_opts "$@"
123+
124+
url_path="$1"
125+
shift || :
126+
127+
url_path="${url_path//https:\\/\\/*.make.com\/api/v2}"
128+
url_path="${url_path##/}"
129+
130+
export CURL_AUTH_HEADER="Authorization: Token"
131+
export TOKEN="$MAKE_API_KEY"
132+
133+
if [[ "$url_path" =~ {organizationId} ]]; then
134+
if [ -z "${MAKE_ORGANIZATION_ID:-}" ]; then
135+
MAKE_ORGANIZATION_ID="$("$0" /organizations | jq -Mr '.organizations[0].id')"
136+
fi
137+
url_path="${url_path/\{organizationId\}/$MAKE_ORGANIZATION_ID}"
138+
fi
139+
140+
"$srcdir/../bin/curl_auth.sh" "$url_base/$url_path" ${CURL_OPTS:+"${CURL_OPTS[@]}"} "$@" |
141+
jq_debug_pipe_dump

0 commit comments

Comments
 (0)