{"id":5158,"date":"2016-10-18T12:14:50","date_gmt":"2016-10-18T12:14:50","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5158"},"modified":"2016-10-18T12:14:50","modified_gmt":"2016-10-18T12:14:50","slug":"using-cloudflare-api-clear-cache-enable-development-mode","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/using-cloudflare-api-clear-cache-enable-development-mode\/","title":{"rendered":"Using the Cloudflare API to clear the cache and Enable Development Mode"},"content":{"rendered":"<p>If you use Cloudflare for caching, clearing the cache is an important part of the deployment. You may also wish to enable Development Mode (this temporarily disables the cache).<\/p>\n<p>Below, I placed instructions for doing both, adapted from a very helpful example<sup><a href=\"#footnote_0_5158\" id=\"identifier_0_5158\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/progressivethink.in\/on\/administration\/and\/clear-cloudflare-cache-on-commit\/\">1<\/a><\/sup>, with Development Mode added<sup><a href=\"#footnote_1_5158\" id=\"identifier_1_5158\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/api.cloudflare.com\/#zone-settings-change-development-mode-setting\">2<\/a><\/sup>. <\/p>\n<p>To run this, you&#8217;ll need to fill in the account email, domain, and the API key, which you can obtain from Cloudflare&#8217;s settings.<\/p>\n<pre lang=\"bash\">\nemail=gary.sieling@gmail.com\ntkn=<API KEY>\ndomain=findlectures.com\n\nzone=$(curl -s -X GET \"https:\/\/api.CloudFlare.com\/client\/v4\/zones?name=${domain}&status=active&page=1&per_page=20&order=status&direction=desc&match=all\" \\\n-H \"X-Auth-Email: ${email}\" \\\n-H \"X-Auth-Key: ${tkn}\" \\\n-H \"Content-Type: application\/json\")\n\nzone=${zone:18:32}\n\ncurl -X DELETE \"https:\/\/api.CloudFlare.com\/client\/v4\/zones\/${zone}\/purge_cache\" \\\n-H \"X-Auth-Email: ${email}\" \\\n-H \"X-Auth-Key: ${tkn}\" \\\n-H \"Content-Type: application\/json\" \\\n--data '{\"purge_everything\":true}'\n\ncurl -X PATCH \"https:\/\/api.cloudflare.com\/client\/v4\/zones\/${zone}\/settings\/development_mode\" \\\n     -H \"X-Auth-Email: ${email}\" \\\n     -H \"X-Auth-Key: ${tkn}\" \\\n     -H \"Content-Type: application\/json\" \\\n     --data '{\"value\":\"on\"}'\n\nunset zone email tkn domain\n<\/pre>\n<p>If this works, you&#8217;ll see results like this:<\/p>\n<pre lang=\"javascript\">\n{\"result\":{\"id\":\"9ae4406845fb8eb20edbe263d4830ec6\"},\n\"success\":true,\"errors\":[],\"messages\":[]}\n{\"result\":{\"id\":\"development_mode\",\"value\":\"on\",\n\"modified_on\":\"2016-10-18T12:06:34.161265Z\",\"time_remaining\":10800,\"editable\":true},\n\"success\":true,\"errors\":[],\"messages\":[]}\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_5158\" class=\"footnote\">https:\/\/progressivethink.in\/on\/administration\/and\/clear-cloudflare-cache-on-commit\/<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_5158\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_1_5158\" class=\"footnote\">https:\/\/api.cloudflare.com\/#zone-settings-change-development-mode-setting<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_1_5158\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Using Cloudflare&#8217;s API to automate deployment tasks<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12],"tags":[113,169],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5158"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5158"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5158\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}