This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How can I call pingdom api delete maintenance?

Hello,

I try to use an API to delete maintenance set on monitors, at the end of my technical operation.

I read the following documentation: docs.pingdom.com/.../

And this helped me to write the following SHELL script

now_epoch=$(date +%s)
for maintid in ${maintenanceids}; do
  echo -e "0-Working on ${maintid}"
  curl -X GET -sS -H "Authorization: Bearer ${PINGDOM_TOKEN}"     "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -er '.'
  maintenance_end=0
  filter_description="${TENANT} muted by script"
  maintenance_end=$(curl -X GET -sS -H "Authorization: Bearer ${PINGDOM_TOKEN}"     "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -er --arg F_DESCRIPTION "${filter_description}" '.maintenance | select (.description == $F_DESCRIPTION) | .to')
  echo -e "1-Maintenance_end ::${maintenance_end}:: now_epoch ::${now_epoch}::"
  if [[ "${maintenance_end}" -gt "${now_epoch}" ]]; then
    echo -e "\t 2-CAN BE STOPPED"
    echo -e "\t\t 3-GET https://api.pingdom.com/api/3.1/maintenance/${maintid}"
    curl -X -sS GET -H "Authorization: Bearer ${PINGDOM_TOKEN}"       "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -r '.'
    echo -e "\t\t 4-DELETE https://api.pingdom.com/api/3.1/maintenance/${maintid}"
    curl -X DELETE -H "Authorization: Bearer ${PINGDOM_TOKEN}"       "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -r '.'
  else
    echo -e "\t ---NO NEED TO STOP MAINTENANCE"
  fi
done

Yet, my DELETE maintenance API call ends with a 404 error. 

Here is the script output, in case I find a maintenance that I need to delete:

0-Working on 159819
{
  "maintenance": {
    "id": 159819,
    "description": "xxxxx muted by script",
    "from": 1602858337,
    "to": 1602858636,
    "duration": 4,
    "durationunit": "minute",
    "recurrencetype": "none",
    "repeatevery": 0,
    "dayofweekinmonth": 0,
    "effectiveto": 1602858636,
    "checks": {
      "uptime": [
        6352482,
        6352483,
        6352484
      ],
      "tms": []
    }
  }
}
1-Maintenance_end ::1602858636:: now_epoch ::1602858350::
	 2-CAN BE STOPPED
		 3-GET https://api.pingdom.com/api/3.1/maintenance/159819
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   291  100   291    0     0   1961      0 --:--:-- --:--:-- --:--:--  1966
{
  "maintenance": {
    "id": 159819,
    "description": "xxxxx muted by script",
    "from": 1602858337,
    "to": 1602858636,
    "duration": 4,
    "durationunit": "minute",
    "recurrencetype": "none",
    "repeatevery": 0,
    "dayofweekinmonth": 0,
    "effectiveto": 1602858636,
    "checks": {
      "uptime": [
        6352482,
        6352483,
        6352484
      ],
      "tms": []
    }
  }
}
		 4-DELETE https://api.pingdom.com/api/3.1/maintenance/159819
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   106  100   106    0     0    731      0 --:--:-- --:--:-- --:--:--   736
{
  "error": {
    "statuscode": 404,
    "statusdesc": "Not Found",
    "errormessage": "Please specify a valid API resource"
  }
}

Can you tell me how to invoque properly this API?

Thanks in advance,

Thomas