I have a JSON dump that I am trying to post to a another application. In the payload there is a "pageGroups": "['TEST_TCIS:Oncall Schedule']",
and the double quotes need to be removed to represent this output to pass the data: "pageGroups": ['TEST_TCIS:Oncall Schedule'],
I have tried to use replace
but it fails. If I manually remove the double quotes out of the JSON payload it works.
Here is the code:
api_url_base = "some url"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer some token"
}
data = {"abendCode": "",
"action": "CREATE",
"assignGroup": "TCIS-APP-SUPPORT",
"component": "tcis",
"description": "Test incident creation",
"entered": "", "logicalName": "tcis",
"pageGroups": "['TEST_TCIS:Oncall Schedule']",
"priority": "",
"racfId": "",
"sendPage": "",
"sysProdName": "tcis",
"transactionId": "",
"type": "SYSMAN"}
data = json.dumps(data)
data = data.replace("\"[", "[").replace("]\"", "]")
print(data)
response = requests.post("https://apistaging.csx.com/tcis-events/v1/events",
json=data, headers=headers)
response_url = json.loads(response.content.decode('utf-8'))
print(response_url)
print("response " + str(response))
Here is the output I am getting:
{"abendCode": "",
"action": "CREATE",
"assignGroup": "TCIS-APP-SUPPORT",
"component": "tcis",
"description": "Test incident creation",
"entered": "",
"logicalName": "tcis",
"pageGroups": ['TEST_TCIS:Oncall Schedule'],
"priority": "",
"racfId": "",
"sendPage": "",
"sysProdName": "tcis",
"transactionId": "",
"type": "SYSMAN"}
{'traceId': 'd9dcd6ee-a0f3-170c-83e5-a52f2133cd31', 'error': {'code': 'APG400', 'message': 'The server could not process the request.'}}
response <Response [400]>
[Finished in 0.789s]