Tuesday 15 February 2011

django - Trouble initiating webhook using shopify_python_api -



django - Trouble initiating webhook using shopify_python_api -

i using sample application https://github.com/shopify/shopify_django_app , trying find best place create webhooks. below finalize method sample code , i'm trying create webhooks after session created.

def finalize(request): shop_url = request.request.get('shop') try: shopify_session = shopify.session(shop_url) request.session['shopify'] = { "shop_url": shop_url, "access_token": shopify_session.request_token(request.request) } #create webhooks shopify.shopifyresource.activate_session(shopify_session) product_hook = shopify.webhook() product_hook.topic ='products/create' product_hook.address = settings.shopify_app_url + '/notify/product/' product_hook.format = 'json' product_hook.save() except exception, err: log.error(str(err)) messages.error(request, "could not log in shopify store.") homecoming redirect(reverse('shopify_app.views.login')) messages.info(request, "logged in shopify store.") response = redirect(_return_address(request)) request.session.pop('return_to', none) homecoming response

i'm not getting in log appears past webhook creation. however, no webhook created , django error:

noreversematch @ /finalize/ reverse 'root_path' arguments '()' , keyword arguments '{}' not found. 0 pattern(s) tried: []

any insight i'm doing wrong appreciated.

here views.py illustration app:

from django.shortcuts import render_to_response, redirect django.contrib import messages django.core.urlresolvers import reverse django.template import requestcontext django.conf import settings import shopify def _return_address(request): homecoming request.session.get('return_to') or reverse('root_path') def login(request): # inquire user ${shop}.myshopify.com address # if ${shop}.myshopify.com address provided in url, # skip authenticate if request.request.get('shop'): homecoming authenticate(request) homecoming render_to_response('shopify_app/login.html', {}, context_instance=requestcontext(request)) def authenticate(request): shop = request.request.get('shop') if shop: scope = settings.shopify_api_scope redirect_uri = request.build_absolute_uri(reverse('shopify_app.views.finalize')) permission_url = shopify.session(shop.strip()).create_permission_url(scope, redirect_uri) homecoming redirect(permission_url) homecoming redirect(_return_address(request)) def finalize(request): shop_url = request.request.get('shop') try: shopify_session = shopify.session(shop_url) request.session['shopify'] = { "shop_url": shop_url, "access_token": shopify_session.request_token(request.request) } except exception: messages.error(request, "could not log in shopify store.") homecoming redirect(reverse('shopify_app.views.login')) messages.info(request, "logged in shopify store.") response = redirect(_return_address(request)) request.session.pop('return_to', none) homecoming response def logout(request): request.session.pop('shopify', none) messages.info(request, "successfully logged out.") homecoming redirect(reverse('shopify_app.views.login'))

adding urls.py

from django.conf.urls import patterns, include, url django.contrib import admin urlpatterns = patterns('', url(r'^$', 'shopify_app.views.login'), url(r'^admin/', include(admin.site.urls)), url(r'^login/', 'shopify_app.views.login'), url(r'^authenticate/$', 'shopify_app.views.authenticate'), url(r'^finalize/$', 'shopify_app.views.finalize'), url(r'^logout/$', 'shopify_app.views.logout'), )

django shopify

No comments:

Post a Comment