Uninstall a Shopify app with an API call
There are situations where an app will be required to remove old installations from the system. In cases where user intervention is not required, you can send a request to Shopify API to remove an app from a shop.
Uninstalling an application also performs various cleanup tasks within Shopify. This includes deleting any registered webhooks, script tags, and admin links. If an app is uninstalled during key rotation, then both the old and new access tokens will become unusable.
Example implementations
Ruby
The following example shows a simple way to revoke API access:
require 'rest_client'
require 'json'
access_token = 'secret'
revoke_url = 'https://{shop}.myshopify.com/admin/api_permissions/current.json'
headers = {
'X-Shopify-Access-Token' => access_token,
content_type: 'application/json',
accept: 'application/json'
}
response = RestClient.delete(revoke_url, headers)
response.code # 200 for success
PHP
The following example shows a simple way to revoke API access:
<?php
$access_token = "secret";
$revoke_url = "https://{shop}.myshopify.com/admin/api_permissions/current.json"
$headers = array(
"Content-Type: application/json",
"Accept: application/json",
"Content-Length: 0",
"X-Shopify-Access-Token: " . $access_token
);
$handler = curl_init($revoke_url);
curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
curl_exec($handler);
if(!curl_errno($handler))
{
$info = curl_getinfo($handler);
// $info['http_code'] == 200 for success
}
curl_close($handler);
?>