Skip to content

Instantly share code, notes, and snippets.

@remy727
Last active January 5, 2024 19:12
Show Gist options
  • Save remy727/cbfaeabfcb83afb070ef3ddb6e76f97e to your computer and use it in GitHub Desktop.
Save remy727/cbfaeabfcb83afb070ef3ddb6e76f97e to your computer and use it in GitHub Desktop.
Retrieve Shopify App uninstall surveys
org_id = 'your_org_id'
access_token = 'your_partner_api_access_token'
api_version = 'shopify_api_version' # example: '2024-01'
app_id = "gid://partners/App/your_app_id"
occurred_at_min = 'specific_time' # example: '2024-01-02T23:15:27.000000Z'
uri = URI("https://partners.shopify.com/#{org_id}/api/#{api_version}/graphql.json")
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['X-Shopify-Access-Token'] = access_token
request.body = {
query: "
query($appId: ID!, $occurredAtMin: DateTime!) {
app(id: $appId) {
events(types: RELATIONSHIP_UNINSTALLED, occurredAtMin: $occurredAtMin) {
edges {
node {
... on RelationshipUninstalled {
shop {
id
name
myshopifyDomain
}
type
reason
occurredAt
}
}
}
}
}
}",
variables: {
occurredAtMin: occurred_at_min,
appId: app_id,
},
}.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
result = JSON.parse(response.body)
surveys = result.dig('data', 'app', 'events', 'edges')
surveys.map do |survey|
{
'shop_name' => survey.dig('node', 'shop', 'name'),
'myshopify_domain' => survey.dig('node', 'shop', 'myshopifyDomain'),
'reason' => survey.dig('node', 'reason'),
'occurred_at' => survey.dig('node', 'occurredAt'),
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment