Reputation: 55
I'm trying to make a python POST request, based on data that I get from a separate GET request.
Get request functions properly, and I get a response that looks like:
{
"meta": {},
"linked": {}
"data": [
{
"date_on_hold": null,
"cc": [],
"agent": 8,
"person": 210
"fields": {
"1": {
"value": "nellson.dom",
"aliases": []
}
}
]
I put some of that data into a few lists (omitted) but when I try to perform a POST request like this:
data = {"subject": "Testing POST request", "person": 210, "agent": 8, "[fields][1][data]": "nellson.dom" }
data = json.dumps(data)
postResponse = requests.post(url=URL, headers=headers, data=data)
print(postResponse.status_code)
print(postResponse.text)
I get a 400 error code, with message: "Unexpected field names: "[fields][1][value]""
Am I doing something wrong here? How might I go about posting the data at [data][fields][1][value]?
I want to add, that if I got rid of that particular field in the data section so it would look like:
data = {"subject": "Testing POST request", "person": 210, "agent": 8}
Everything functions properly.
Upvotes: 1
Views: 647
Reputation: 26
"[fields][1][data]"
at the POST request is used as a key, and it's considered as a string since it's inside double quotes, but this isn't what you want.
If you want to get the "value" key which inside the first dict of the "fields" key to be used as a param key at your POST request, check the following key matching:
Regarding this is the GET response
get_response = {
"meta" : {},
"linked": {},
"data" : [
{
"date_on_hold": null,
"cc" : [],
"agent" : 8,
"person" : 210,
"fields" : {
"1": {
"value" : "nellson.dom",
"aliases": []
}
},
}
]
}
data = {"subject": "Testing POST request", "person": 210, "agent": 8, list(get_response["data"][0]["fields"]["1"].keys())[0]: "nellson.dom" }
Upvotes: 1