Uninstall app by API call

niels-hecquard
Tourist
3 0 3

Hi,

 

I'm working on an app and I'd like to be able to uninstall it from a shop by an API call.
I saw this tutorial which tells it's possible : https://shopify.dev/tutorials/uninstall-an-app-with-an-api-call

But when I call it I get a 403 error with response :

"errors""Scope undefined for API access: api_permissions. Valid scopes: ..."
And I didn't find anything related to this endpoint in the docs.
 
Thanks for your help,
Niels
0 Likes
niels-hecquard
Tourist
3 0 3

Ok I was just not doing a DELETE request

m20io
New Member
3 0 0

Hi do you have an example of how to make the call?

I followed the example in the documentation, but I'm always getting a permissions error. Also with a delete call?

Are you using the regular shopify token for the call? (Like for all other shopify API calls?)

0 Likes
m20io
New Member
3 0 0

I'm always getting an error:

"[API] Invalid API key or access token (unrecognized login or wrong password)"
0 Likes
niels-hecquard
Tourist
3 0 3

Hi,

 

Yes a DELETE request with the X-Shopify-Access-Token is all you need I think.

 

My code example :

 

    public Boolean uninstall(String host) {
        UriComponentsBuilder uriBuilder = UriComponentsBuilder
                .fromHttpUrl(format("https://%s/admin/api_permissions/current.json", host));

        URI endpoint = uriBuilder.build().toUri();
        HttpHeaders headers = new HttpHeaders();
        headers.add(ACCESS_TOKEN_HEADER, TOKEN);
        headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
        HttpEntity entity = new HttpEntity(headers);

        HttpStatus responseStatus = restRepeater(() ->
                jsonRestTemplate.exchange(endpoint, HttpMethod.DELETE, entity, String.class).getStatusCode()
        );
        return responseStatus == HttpStatus.OK;
    }

A little warning to the uninstall functionality just in case : it's for dev purposes only. You can't call this API when the app goes public (my app has been refused for that) ;)