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
| export ZONE_ID=7b3f2ff4b23ab88aa09326590263561b
export RECORD=apple.willschenk.com
export IP=65.108.63.49
RECORD_ID=$(
curl -X GET \
https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?name=${RECORD} \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${CF_TOKEN}" | \
jq -r '{"result"}[] | .[0] | .id')
if [[ $RECORD_ID == 'null' ]]; then
echo Creating ${RECORD}
jo type=A name=${RECORD} content=${IP} ttl=1 proxied=false | \
curl -X POST \
https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records \
-d @- \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${CF_TOKEN}" | \
jq
else
echo Updating $RECORD_ID
jo type=A name=${RECORD} content=${IP} ttl=1 proxied=false | \
curl -X PUT \
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \
-d @- \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${CF_TOKEN}" | \
jq
fi
|
This first checks to see if there's already an A
record, and if not it
created one. Otherwise, it updates it.
Either way it returns the latest info.
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
| Creating apple.willschenk.com
{
"result": {
"id": "425a21b7d74e958230f9f50d82adc836",
"zone_id": "7b3f2ff4b23ab88aa09326590263561b",
"zone_name": "willschenk.com",
"name": "apple.willschenk.com",
"type": "A",
"content": "65.108.63.49",
"proxiable": true,
"proxied": false,
"ttl": 1,
"locked": false,
"meta": {
"auto_added": false,
"managed_by_apps": false,
"managed_by_argo_tunnel": false,
"source": "primary"
},
"comment": null,
"tags": [],
"created_on": "2023-06-20T17:30:53.819641Z",
"modified_on": "2023-06-20T17:30:53.819641Z"
},
"success": true,
"errors": [],
"messages": []
}
|