How to get a "Naming Series" through the REST API?

Like I said, I had to put this on the back burner. But …

Here’s a script for anyone who’d like to give it a try:

export YOUR_HOST="http://YOURHOST";
export YOUR_TOKEN="60e..KEY..115:5a4..SECRET..97a";
export YOUR_SERIES="Webhook";
export YOUR_TEMPLATE="WHK-.####";

Get modification date…

export REST_ENDPOINT="${YOUR_HOST}/api/resource";
export RPC_ENDPOINT="${YOUR_HOST}/api/method";
export DATE_MODIFIED=$(curl -s "${REST_ENDPOINT}/Naming Series/Naming Series" -H "Authorization: token ${YOUR_TOKEN}" | jq -r .data.modified);

Get current series formatting templates for Webhook …

cat << NSEOF > /dev/shm/SeriesSpec.json;
{
    "method": "get_options",
    "docs": "{\"name\":\"Naming Series\",\"doctype\":\"Naming Series\",\"select_doc_for_series\":\"Webhook\",\"modified\":\"${DATE_MODIFIED}\"}"
}
NSEOF

cat /dev/shm/SeriesSpec.json;

curl -sX POST "${RPC_ENDPOINT}/runserverobj" \
  -H "Authorization: token ${YOUR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d @/dev/shm/SeriesSpec.json > /dev/shm/OldSeries.json;

export OLD_TEMPLATES=$(cat /dev/shm/OldSeries.json | jq -r .message);
echo -e "
Existing templates:
${OLD_TEMPLATES}";

Update Webhook series formatting templates …

cat << UPEOF > /dev/shm/SeriesUpdate.json;
{
     "method": "update_series",
     "docs": "{\"name\":\"Naming Series\",\"doctype\":\"Naming Series\",\"select_doc_for_series\":\"Webhook\",\"set_options\":\"\\\nHOOK-.####\\\nWHK-.####\",\"modified\":\"${DATE_MODIFIED}\"}"
}
UPEOF

cat /dev/shm/SeriesUpdate.json;

curl -sX POST "${RPC_ENDPOINT}/runserverobj" \
  -H "Authorization: token ${YOUR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d @/dev/shm/SeriesUpdate.json | jq -r .;

Get revised series formatting templates …

curl -sX POST "${RPC_ENDPOINT}/runserverobj" \
  -H "Authorization: token ${YOUR_TOKEN}" \
  -H "Content-Type: application/json" \
  -d @/dev/shm/SeriesSpec.json > /dev/shm/NewSeries.json;

cat /dev/shm/NewSeries.json | jq -r .message;

export REVISED_TEMPLATES=$(cat /dev/shm/NewSeries.json | jq -r .message);
echo -e "
Prior templates: \n${OLD_TEMPLATES}

Updated templates: \n${REVISED_TEMPLATES}";

Update 2020/06/05 ==> To update the current value of an existing naming series see the forum topic How to set a "Naming Series" sequence start number through the RPC API? - #3 by MartinHBramwell