Existing records not returned in REST API

Due to Subdomain Single/Multi Zone
I ended up writing a shell script which basically does the following via the rest api:

  1. Check for existence of A record for home.abc.de
  2. if record is not present add it with current ip address
  3. if record is present, compare it to the current dynamic ip address and change it, if it is different to the current one

It seems that from time to time a record in the zone in the rest api is not returned even though it exists (I can see it in the web interface).

Symptom is that I end up with many duplicate A records (about per 2 day if I check every 10 minutes) in the zone. The duplicates are not directly a problem but if the ip address changes there is are differing/contradicting records present.
Has anybody experienced the same problem?

Yes, I did. Due to another issue (see AAAA record got lost) I have my records checked periodically - not via the REST API, but with cyclic “dig @nsX.dynv6.com” where X in (1,2,3).
If the dig fails then the corresponding record is restored via the REST API.
It appears however that the API doesn’t always reflect the actual status of the NS.
From time to time this results in duplicate records. So I’ve created a shell script that checks for duplicates and deletes the most recent one(s), if present.

Here’s the script:

# remove duplicate records from server
# requires jq to be installed

# settings
if [ X != X$1 ]
RECORDS_A=('louie' 'huey' 'dewey' 'foo' 'bar')
RECORDS_AAAA=('louie' 'huey' 'dewey' 'foo' 'bar' '')

# determine current status
curl -sS --fail \
   -H "Authorization: Bearer $TOKEN" \
   -H "Accept: application/json" \
   https://dynv6.com/api/v2/zones/$ZONEID/records \

 for TYPE in "${TYPES[@]}"
   for NAME in "${RECORDS_AAAA[@]}"
     ID=$( jq 'map (select(.type=="'$TYPE'") | select(.name=="'$NAME'")) | .[].id' "$TEMPFILE") # contains all IDs for a specific record
     NUM_IDS=`echo $ID | wc -w` # how many IDs exist for this record?
     while [ $NUM_IDS -gt 1 ]
     do  # remove redundant
       LATEST_ID=$( echo $ID | gawk '{print $(NF)}' ) # get last ID...
       echo  `date --rfc-3339=seconds` "deleting duplicate record '$TYPE' '$NAME' $LATEST_ID"
       ID=${ID//$LATEST_ID/ } # ...and remove it from the list (just replace with empty string)
       NUM_IDS=`echo $ID | wc -w`
       curl -sS --fail \
            -X DELETE \
            -H "Authorization: Bearer $TOKEN" \
            -H "Accept: application/json" \
            https://dynv6.com/api/v2/zones/$ZONEID/records/$LATEST_ID # remove record 

Hope this helps!