I believe your issue is related to this recent bug in the issue tracker.
http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3346
Question
I have authenticated my request and I'm trying to create a customer in the sandbox but I always receive a error 500.
This is the request:
self.cred = OAuth2Credentials(access_token = access_token, client_id = client_id,
client_secret = client_secret, refresh_token = refresh_token,
token_expiry = None, token_uri ="https://accounts.google.com/o/oauth2/token",
user_agent = None, id_token = None)
self.client = httplib2.Http()
self.cred.refresh(self.client)
self.client = self.cred.authorize(self.client)
payload = {
"kind": "reseller#customer",
"customerId": "example.com",
"customerDomain": "example.com",
"postalAddress": {
"kind": "customers#address",
"contactName": "John Doe",
"organizationName": "Example Inc",
"locality": "Mountain View",
"region": "California",
"postalCode": "94043",
"countryCode": "US",
"addressLine1": "1600 Amphitheatre Parkway",
"addressLine2": "Mountain View",
"addressLine3": "California"
},
"phoneNumber": "+1 650-253-0000",
"alternateEmail": "alternateEmail@google.com"
}
paytext = json.dumps(payload)
da = self.client.request(method = 'POST', uri = "https://www.googleapis.com/apps/reseller/v1sandbox/customers/", body =paytext)
This is the error:
({'status': '500', 'content-length': '52', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'expires': 'Thu, 21 Feb 2013 11:09:51 GMT', 'server': 'GSE', '-content-encoding': 'gzip', 'cache-control': 'private, max-age=0', 'date': 'Thu, 21 Feb 2013 11:09:51 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-type': 'application/json; charset=UTF-8'}, '{\n "error": {\n "code": 500,\n "message": null\n }\n}\n')
Is there any other way to do this?
Edit:
I've also tried with the discovery:
from apiclient.discovery import build
import httplib2
http = httplib2.Http()
from oauth2client.client import OAuth2Credentials
cred = OAuth2Credentials(access_token = access_token, client_id = client_id,
client_secret = client_secret, refresh_token = refresh_token,
token_expiry = None, token_uri ="https://accounts.google.com/o/oauth2/token" ,
user_agent = None, id_token = None)
client = httplib2.Http()
cred.refresh(client)
client = cred.authorize(client)
api = build(serviceName='reseller',version='v1sandbox',http=client)
api.customers().insert(body=payload).execute()
And there is an error too.
Solution
I believe your issue is related to this recent bug in the issue tracker.
http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3346
OTHER TIPS
I think they've fixed their bug, though it doesn't appear to be marked as fixed. We were able to create a sandbox customer with. Here's the gist in Ruby:
def self.create
response = client.execute(
:api_method => service.customers.insert,
:body_object => {
:customerDomain => domain,
:alternateEmail => alternate_email,
:postalAddress => {
:contactName => contact_name,
:organizationName => organization_name,
:countryCode => two_letter_country_code,
:region => region,
:addressLine1 => street_address,
:locality => city,
:postalCode => zip
}
},
:authorization => authorization )
GoogleCustomer.new(response.data)
end
This seems to be the minimum information necessary to create a customer.
This assumes you've already handled the authorization. One thing to note: if you're using a service account you need to impersonate a user with access to create customers.