Lloyd | 2020-04-14 22:25:02 UTC | #1
Trying to add anew response to an existing response Group using the API. (I'm using Python to do this)
I can successfully create my request Headers & can verify this by making other API calls.
I have a hardcoded response for testing purposes and am using the following code:
print('\nREQUEST BODY')
requestBodyDict = { "name": "Test2", "libraries": [ { "id": "8bb51e2e-3341-49bf-a204-bd85b4fecb0d", "name": "Lloyd Bulk Upload Test", "selfUri": "/api/v2/responsemanagement/libraries/8bb51e2e-3341-49bf-a204-bd85b4fecb0d" } ], "texts": [ { "content": "hello", "contentType": "text/html" } ] }
print(json.dumps(requestBodyDict, indent=4, sort_keys=True))
requestUrl = platformAPI + '/api/v2/responsemanagement/responses' print('\nREQUEST URL') print(requestUrl)
requestBodyJson = json.dumps(requestBodyDict) response = requests.post(requestUrl, headers=requestHeaders, data=requestBodyJson)
print('\nRESPONSE') print(response) print(json.dumps(response.json(), indent=4, sort_keys=True))
When I run I get the following output and error code
AUTHORISING & DEFINING REQUEST HEADERS
- Got Token!
- requestHeaders Defined
REQUEST BODY { "libraries": [ { "id": "8bb51e2e-3341-49bf-a204-bd85b4fecb0d", "name": "Lloyd Bulk Upload Test", "selfUri": "/api/v2/responsemanagement/libraries/8bb51e2e-3341-49bf-a204-bd85b4fecb0d" } ], "name": "Test2", "texts": [ { "content": "hello", "contentType": "text/html" } ] }
REQUEST URL https://api.mypurecloud.com.au/api/v2/responsemanagement/responses
RESPONSE <Response [500]> { "code": "internal.server.error", "contextId": "607a5a82-9bdd-4c1d-a4da-e59d324932a9", "details": [], "errors": [], "message": "Unable to add response text document", "status": 500 }
However if I copy the displayed Request Body into the API explorer and run it against /api/v2/responsemanagement/responses then I get a 200/OK and the following response
{ "id": "37cb12ad-8598-4f70-aaa9-55698798af05", "name": "Test2", "version": 1, "libraries": [ { "id": "8bb51e2e-3341-49bf-a204-bd85b4fecb0d", "name": "Lloyd Bulk Upload Test", "selfUri": "/api/v2/responsemanagement/libraries/8bb51e2e-3341-49bf-a204-bd85b4fecb0d" } ], "texts": [ { "content": "hello", "contentType": "text/html" } ], "createdBy": { "id": "d64c128c-171d-4344-b275-828fa8defdd4", "selfUri": "/api/v2/users/d64c128c-171d-4344-b275-828fa8defdd4" }, "dateCreated": "2020-04-14T21:56:18.677Z", "substitutions": [], "selfUri": "/api/v2/responsemanagement/responses/37cb12ad-8598-4f70-aaa9-55698798af05" }
Looking for clues as to what I'm doing wrong in my request to trigger a Server 500 error. Thanks
tim.smith | 2020-04-14 22:31:35 UTC | #2
The short answer is that you can't use this endpoint with client credentials. That's why it works in API Explorer (authorizes using your user) and not in your app.
However, the fact that it's returning a 500 is a bug and should be reported to Genesys Cloud Care for investigation. I can't say for certain that this operation isn't supposed to work for client credentials; that may be a bug. But at a minimum, this should be returning a 400 with the not.a.user error code. Care can investigate to determine what needs to be fixed here.
Lloyd | 2020-04-14 22:34:17 UTC | #3
ahhh - Bother. Time for a re-design... :slight_smile:
Thanks for clarifying that Tim
Cheers L
tim.smith | 2020-04-14 22:35:54 UTC | #4
It's worth opening a case with Care before you redesign. The backend error indicates that the operation isn't properly checking for a user vs. client creds; it's not an explicit denial.
Lloyd | 2020-04-14 22:55:38 UTC | #5
Cheers Tim - Have just raised that now
Lloyd | 2020-04-15 21:21:46 UTC | #6
Tim - Thanks again for your help. Converted my code to use code authorization & it's now working perfectly.
system | 2020-05-16 21:21:48 UTC | #7
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 7544