from shopify_trois import Credentials, Collection
from shopify_trois.models import *
from shopify_trois.engines.http import Json as Shopify
credentials = Credentials(
api_key='your api key',
scope=['read_content', 'write_orders'],
secret='your api key secret'
)
shopify = Shopify(shop_name="your store name", credentials=credentials)
# Redirect the shop owner to the URL provided by `shopify.oauth_authorize_url()`
# print(shopify.oauth_authorize_url())
# Get the oauth temporary code and set it in the credentials object.
credentials.code = "oauth temporary code"
# fetch the access token
shopify.setup_access_token()
# credentials.oauth_access_token will contain the access token. It would be a good idea to save it somewhere.
credentials = Credentials(
api_key='your api key',
scope=['read_content'],
secret='your app secret',
oauth_access_token="your access token"
)
shopify = Shopify(shop_name="your store name", credentials=credentials)
# The client is now ready to communicate with Shopify
shopify.fetch(Shop).to_dict()
# Fetch the store information
shop = shopify.fetch(Shop)
# Set the shop as public
shop.public = True
# Calling changes() on a model instance will show the modified properties.
print(shop.changes())
webhook = Webhook()
webhook.address = "http://do-not-copy-this.com"
webhook.format = "json"
webhook.topic = "orders/create"
# Create the webhook
shopify.add(webhook)
# Get all the webhooks and iterates them
webhooks = shopify.index(Webhook)
for webhook in webhooks:
# webhook is a Webhook instance, created by iterating the Collection
print(webhook.to_dict())
Shopify-Trois has basic entity relationship support. Some entities have been marked as subresources of another.
shopify.index(ProductVariant, parent_id=2)
variant = ProductVariant(id=123, product_id=2)
shopify.fetch(variant)
Shopify-Trois exposes metafields as it do for relationships.
Note: The ProductVariant metafield is currently unsupported.
shopify.index(BlogMetafield, parent_id=234224)
metafield = BlogMetafield(id=2342, blog_id=3242424)
shopify.fetch(metafield)
Shopify-Trois can easily access multiple shops within the same thread.
from shopify_trois import Credentials
from shopify_trois.models import Shop
from shopify_trois.engines.http import Json as Shopify
credentials = {
"a-store-name": Credentials(
api_key='your-app-key',
secret='your-app-secret',
oauth_access_token='access-token',
scope=['read_content']
),
"another-store-name": Credentials(
api_key='your-app-key',
secret='your-app-secret',
oauth_access_token='access-token',
scope=['read_content']
)
}
instances = [Shopify(shop_name=k, credentials=v) for k, v in credentials.items()]
stores = [instance.fetch(Shop) for instance in instances]
for store in stores:
print(store.name)
The Json engine implements an HTTP transport using JSON with OAuth authentication.
Parameters: |
|
---|
Add the model instance to the store.
Parameters: |
|
---|
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blog = Blog(title="Awesome")
shopify.add(blog)
Generates the oauth authorization url.
Return the count of a model, filtered by parameters
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blogs = shopify.count(Blog)
Executes a custom post method on an instance.
Parameters: |
|
---|
Delete a model instance.
An InvalidRequestException will be raised if the instance does not yet exists.
Parameters: |
|
---|
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blog = Blog(id=3)
shopify.delete(blog)
Get a specific model instance by primary key.
Parameters: |
|
---|
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blog = shopify.fetch(Blog, 2)
When set to True, ignore checking for supported actions on models.
Fetch the index for a given model and supplied parameters.
Parameters: |
|
---|
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blogs = shopify.index(Blog)
for blog in blogs:
print(blog.to_dict())
Fetch the OAuth access token from shopify.
setup_access_token() should be used.
Generate the OAuth access token url.
Generates the oauth authorize url.
Parameters: | redirect_to – URL shopify will redirect to once authorized. |
---|
Utility function wrapping getting the oauth token and setting the credential values.
Utility method to sync the credentials access token with the HTTP session.
Update a model instance.
An InvalidRequestException will be raised if the instance has not been marked as existing.
Parameters: |
|
---|
example usage:
from shopify_trois.engines.http import Json as Shopify
from shopify_trois import Credentials
from shopify_trois.models import Blog
credentials = Credentials(...)
shopify = Shopify(store_name="test", credentials=credentials)
blog = shopify.fetch(Blog, 4)
blog.commentable = False
shopify.update(blog)
Generates the url for the provided request.
Parameters: | req – See Request |
---|
Verify the signature provided with the query parameters.
http://docs.shopify.com/api/tutorials/oauth
example usage:
from shopify_trois import Credentials
from shopify_trois.engines import Json as Shopify
from urllib.parse import parse_qsl
credentials = Credentials(
api_key='your_api_key',
scope=['read_orders'],
secret='your_app_secret'
)
shopify = Shopify(shop_name="your_store_name", credentials= credentials)
query_parameters = parse_qsl("code=238420989938cb70a609f6ece2e2586b&shop=yourstore.myshopify.com×tamp=1373382939&signature=6fb122e33c21851c465345b8cb97245e")
if not shopify.verify_signature(query_parameters):
raise Exception("invalid signature")
credentials.code = dict(query_parameters).get('code')
shopify.setup_access_token()
Returns: | Returns True if the signature is valid. |
---|