Having Trouble with Creating Contact


I am trying to write some python code to talk to the API. I am having trouble creating new entries in the database. A minimal code snippet is below:

import requests
import json

url = 'https://api.sandbox.freeagent.com/v2/contacts/'
headers = {"Accept": "application/json",
           "Authorization": "Bearer ...............................",
           "Content-Type": "application/json"}
data = {"contact": {"first_name": "test", "last_name": "me", "organisation_name": "Acme Ltd"}}

resp = requests.post(url=url, headers=headers, json=json.dumps(data))
print("Server returned {} {} {}".format(resp.status_code, resp.reason, resp.text))

resp = requests.post(url=url, headers=headers, data=data)
print("Server returned {} {} {}".format(resp.status_code, resp.reason, resp.text))

The above attempts produce the following output.

Server returned 422 Unprocessable Entity {"errors":[{"message":"first_name can't be blank"},{"message":"last_name can't be blank"},{"message":"organisation_name can't be blank"}]}
Server returned 400 Bad Request {"error":"Invalid JSON"}

Any help on what is going wrong would be greatly appreciated. (Last ran test code at 23:19)

EDIT: Case closed this code works:
resp = requests.post(url=url, headers=headers, data=json.dumps(data))

Glad you got it figured out, Ron. Let us know if you run into anything else.