This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
class ShopifyCli::PartnersAPI
Kevin O'Sullivan edited this page Jun 28, 2021
·
11 revisions
ShopifyCli::PartnersAPI provides easy access to the partners dashboard CLI schema.
-
LOCAL_DEBUG
Defines the environment variable that this API looks for to operate on local services. If you set this environment variable in your shell then the partners API will operate on your local instance
SHOPIFY_APP_CLI_LOCAL_PARTNERS=1 shopify create
query(ctx, query_name, **variables)
issues a graphql query or mutation to the Shopify Partners Dashboard CLI
Schema. It loads a graphql query from a file so that you do not need to use
large unwieldy query strings. It also handles authentication for you as well.
-
ctx
: running context from your command -
query_name
: name of the query you want to use, loaded from thelib/graphql
directory. -
**variables
: a hash of variables to be supplied to the query or mutation
- http 404 will raise a ShopifyCli::API::APIRequestNotFoundError
- http 400..499 will raise a ShopifyCli::API::APIRequestClientError
- http 500..599 will raise a ShopifyCli::API::APIRequestServerError
- All other codes will raise ShopifyCli::API::APIRequestUnexpectedError
-
resp
- graphql response data hash. This can be a different shape for every query.
ShopifyCli::PartnersAPI.query(@ctx, 'all_organizations')
see source
# File lib/shopify-cli/partners_api.rb, line 47
def query(ctx, query_name, **variables)
CLI::Kit::Util.begin do
api_client(ctx).query(query_name, variables: variables)
end.retry_after(API::APIRequestUnauthorizedError, retries: 1) do
ShopifyCli::IdentityAuth.new(ctx: ctx).reauthenticate
end
rescue API::APIRequestUnauthorizedError => e
if (request_info = auth_failure_info(ctx, e))
ctx.puts(ctx.message("core.api.error.failed_auth_debugging", request_info))
end
ctx.abort(ctx.message("core.api.error.failed_auth"))
rescue API::APIRequestNotFoundError
ctx.puts(ctx.message("core.partners_api.error.account_not_found", ShopifyCli::TOOL_NAME))
end
partners_url_for(organization_id, api_client_id, local_debug)
see source
# File lib/shopify-cli/partners_api.rb, line 62
def partners_url_for(organization_id, api_client_id, local_debug)
if ShopifyCli::Shopifolk.acting_as_shopify_organization?
organization_id = "internal"
end
"#{partners_endpoint(local_debug)}/#{organization_id}/apps/#{api_client_id}"
end
auth_headers(token)
see source
# File lib/shopify-cli/partners_api.rb, line 112
def auth_headers(token)
{ Authorization: "Bearer #{token}" }
end