Hello everone!
I’m trying to make POST requests and am stuck with IronPython but I am having some problems creating records. I’m able to create them using the requests
module in Python3, but I’m not able to replicate this with WebRequest
in IronPython. Here is the code:
def post_request(params):
'''post data to Airtable'''
HEADERS = 'Authorization: Bearer XXXXX'
URI = 'https://api.airtable.com/v0/XXXXXXXXXX/Table%20XX'
request = WebRequest.Create(URI)
request.ContentType = 'application/json'
request.Headers.Add(HEADERS)
request.Method = 'POST'
bytes = Encoding.ASCII.GetBytes(json.dumps(params))
request.ContentLength = bytes.Length
with request.GetRequestStream() as reqStream:
reqStream.Write(bytes, 0, bytes.Length)
response = request.GetResponse()
result = StreamReader(response.GetResponseStream()).ReadToEnd()
return result
The params
are formatted as follows:
params = {
'fields': {
'Room Type': 'Test Room',
'Project': 'Test Proj',
'Room Area (m2)': 15,
}
}
This function has worked to post to other APIs, so I think there’s something wrong with the way the params
are being passed. The error is thrown at response = request.GetResponse()
SystemError: The remote server returned an error: (422) Unprocessable Entity.
Has anyone had any experience with this? I’m not super comfortable with IronPython and am not sure what else I can try. Any help would be greatly appreciated!!
Thank you :sparkles: