question

Jeff Orkin avatar image
Jeff Orkin asked

Example of http post to API?

I am trying to create some admin tools to allow us to manage user accounts. Our back-end is written in Python. Since there is not yet a Python SDK for PlayFab, I am trying to do an http Post request. When I try, I get a 400 error. I am guessing I somehow need to encode my request using the API secret key, but cannot find any examples of how I should do that.

Here is what I am trying to do (in Python):

url = 'https://[titleID].playfabapi.com/Client/RegisterPlayFabUser'
values = {
"TitleId": [titleID],
"Username": "jeffo",
"Email": "jeff@mail.com",
"Password": "xxxxx"
}
headers = {
"Content-Type": "application/json"
}

data = urllib.urlencode(values)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jeff Orkin avatar image
Jeff Orkin answered

Figured it out:

values = {
"TitleId": [titleID],
"Username": "jeffo",
"Email": "jeff@mail.com",
"RequireBothUsernameAndEmail": True,
"Password": "xxxxx"
}

r = requests.post("https://[TitleID].playfabapi.com/Client/RegisterPlayFabUser", json=values)
print r.text

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.