I have spent my day trying to create a CarrierService using the shopify_python_api (https://github.com/Shopify/shopify_python_api).
I tried replicating the example POST request from the API docs:
Create a carrier service POST /admin/carrier_services.json { "carrier_service": {"name": "Shipping Rate Provider","callback_url": "http://shippingrateprovider.com","format": "json","service_discovery": true } }
A short snippet:
import shopify as s c = s.CarrierService() c.name = "Shipping rate provider" c.callback_url = "http://shippingrateprovider.com/callback" c.format = "json" c.service_discovery = "false" c.save()
After getting tired of seeing "422 Unprocessible Entity" I added a few print()s to pyactiveresource, which shows my request:
POST: /admin/carrier_services.json b'{"carrier_service": {"name": "Shipping rate provider", "callback_url": "http://shippingrateprovider.com/callback", "service_discovery": "false"} }'
It turns out that `format` goes missing.
It would seem to come down to these lines pyactiveresource.py:
def __setattr__(self, name, value):"""Set the named attributes. Args: name: The attribute name. value: The attribute's value. Returns: None""" if '_initialized' in self.__dict__: if name in self.__dict__ or getattr(self.__class__, name, None): # Update a normal attribute object.__setattr__(self, name, value) else: # Add/update an attribute self.attributes[name] = value<rest cut out>
I assume that the way it was inteded to work is it to go to the else-block:
self.attributes['format'] = 'json'
But because 'format' is a field in the pyactiveresource object (defines what format it e.g. POSTs in), the 'json' instead goes to
# Update a normal attribute object.__setattr__(self, name, value)
The resulting JSON is generated from 'self.attributes'
Has anyone else encountered this problem or am I doing something wrong?