Development discussions around Shopify APIs
I got an issue following the basic steps for using the API with a private app.
Below is a piece of my code
def __get_session_for_shop(self): shop_url = u'https://%s:%s@%s.myshopify.com/admin' % (self.config.api_key, self.config.password, self.config.store_name) shopify.ShopifyResource.set_site(shop_url) return shopify.Shop.current() # Create product def create_product(self, product): # If we got permission to create a product if self.__valid_request(): print("We can create a product") if ('gtin' in product and shopify.Product.exists(product['gtin'])) or ('GTIN' in product and shopify.Product.exists(product['GTIN'])): pass else: shop = self.__get_session_for_shop() new_product = shopify.Product() new_product.title = "Name of the product" #new_product.handle = "The URL slug of the product" #new_product.product_type = "Category of the product" #new_product.body_html = "Description of the product" #new_product.vendor = "The Manufacturer of the product" #new_product.metafields_global_title_tag = "The meta title" #new_product.metafields_global_description_tag = "The description meta" #new_product.options = self.__get_options(product) #new_product.variants = self.__get_variants(product, new_product.options) saved_successfully = new_product.save() if not saved_successfully: print("Failed at creating")
When i try to save the product i get an issue where it can't parse the port correctly on the url (that little documentation there is, says nothing about a port being specified?)
InvalidURL at /api/v1/products/
nonnumeric port: 'PASSWORD@vuuh-com.myshopify.com'
If i add a :80 to the shop url then i just get another error:
UnicodeError at /api/v1/products/
encoding with 'idna' codec failed (UnicodeError: label empty or too long)
What am i doing wrong ??
The error happens at new_product.save()
Seems i cant remove this myself - can an admin move this to
It sounds like you may be experiencing the issue highlighted in this issue. Can you give this a read over, especially the section at the bottom highlighting a workaround, and let me know if you continue to experience this issue?
Andrew | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Ended up working on a public app instead. So code is fully redone for that.
The workaround works though
@steffenmande i have same issue with Shopify app please post your solution
I'm not really sure about this but I've tried it with the id and it worked, just calling it for some reason made the save return true.
from the docs(https://github.com/Shopify/shopify_python_api😞
product = shopify.Product() product.title = "Shopify Logo T-Shirt" product.id # => 292082188312 product.save() # => True shopify.Product.exists(product.id) # => True product = shopify.Product.find(292082188312) # Resource holding our newly created Product object # Inspect attributes with product.attributes product.price = 19.99 product.save() # => True
We're excited to announce improvements to the threaded messaging experience in our communi...By TyW May 31, 2023
Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...By Jacqui May 30, 2023
Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...By Ollie May 25, 2023