Adrian_Santamaria | 2020-10-23 13:03:20 UTC | #1
Hello
I think I have discovered a little bug with the Datetimes and the Python SDK.
I saw it when I was trying to update a queue's name. So, I tried this:
...Auth stuff...
routing_api = pc2.RoutingApi() try:
Get the queue
queuename = 'mytestqueue' apiresponse: pc2.QueueEntityListing = routingapi.getroutingqueues(name=queuename) retrievedqueue = apiresponse.entities[0]
Modify the queue
retrievedqueue.name = 'mynewtestqueue' apiresponse = routingapi.putroutingqueue(queueid=retrievedqueue.id, body=retrieved_queue)
except IndexError: print('No queues!') except ApiException as e: print('Api error!') raise
However, it gave me this error: {"message":"Dates must be specified as ISO-8601 strings. For example: yyyy-MM-ddTHH:mm:ss.SSSZ","code":"invalid.date","status":400}
First, I thought this was because put_routing_queue expects a QueueRequest object, and I was putting a Queue object (although it should work anyway, as they share the same attributes structure). So, I built a QueueRequest from scrach:
...Auth stuff...
routing_api = pc2.RoutingApi() try:
Get the queue
queuename = 'mytestqueue' apiresponse: pc2.QueueEntityListing = routingapi.getroutingqueues(name=queuename) retrievedqueue = apiresponse.entities[0]
Build the QueueRequest object
queuerequest = pc2.QueueRequest() queuerequest.name = 'mynewtestqueue' queuerequest.division = retrievedqueue.division queuerequest.description = retrievedqueue.description queuerequest.datecreated = retrievedqueue.datecreated queuerequest.datemodified = retrievedqueue.datemodified queuerequest.modifiedby = retrievedqueue.modifiedby queuerequest.createdby = retrievedqueue.createdby queuerequest.membercount = retrievedqueue.membercount queuerequest.mediasettings = retrievedqueue.mediasettings queuerequest.routingrules = retrievedqueue.routingrules queuerequest.bullseye = retrievedqueue.bullseye queuerequest.acwsettings = retrievedqueue.acwsettings queuerequest.skillevaluationmethod = retrievedqueue.skillevaluationmethod queuerequest.queueflow = retrievedqueue.queueflow queuerequest.whisperprompt = retrievedqueue.whisperprompt queuerequest.autoansweronly = retrievedqueue.autoansweronly queuerequest.enabletranscription = retrievedqueue.enabletranscription queuerequest.enablemanualassignment = retrievedqueue.enablemanualassignment queuerequest.callingpartyname = retrievedqueue.callingpartyname queuerequest.defaultscripts = retrievedqueue.defaultscripts queuerequest.outboundmessagingaddresses = retrievedqueue.outboundmessagingaddresses queuerequest.outboundemailaddress = retrievedqueue.outboundemailaddress queuerequest.selfuri = retrievedqueue.self_uri
apiresponse = routingapi.putroutingqueue(queueid=retrievedqueue.id, body=queue_request)
except IndexError: print('No queues!') except ApiException as e: print('Api error!') raise
However, the same error happens again. After some testing, I discovered that if I didn't send the date_created and the date_modified attributes, it would work well. However, that sets those dates to null, which I want to avoid.
So, I think the problem is that somehow the datetime attributes that the get_routing_queues method provides are not accepted by the put_routing_queue method.
John_Carnell | 2020-10-23 14:51:44 UTC | #2
Hi Adrian,
Thanks for the submission. We will take a look at it. I suspect what is happening is what we have seen with our other dynamic language SDKs. If you don't populate the parameter, it does not get sent down to the service and if it is not required then they will not complain about it. However, if you set a value to null, the serializer for the SDK will dutifully send along a string called null.
Thanks again for the post and we will take a look.
Adrian_Santamaria | 2020-10-26 14:30:52 UTC | #3
Hello John
The problem is that I've seen no way to update a Queue using the SDK without overriding the creation and modification dates. If I set the same ones the retrieved Queue object had, it returns error. If I don't, it sets them to null.
After doing some debugging, I think this could be because of how datetime objects are serialized for the request. In the api_client module of the SDK, there is this code:
elif isinstance(obj, (datetime, date)): return obj.isoformat()
This method returns a datetime string like this one: 2020-10-23T12:16:47.843000+00:00, and causes the error. Instead of the +00:00 it should put a 'Z'.
KO:
OK:
John_Carnell | 2020-10-26 19:12:27 UTC | #4
Hi Adrian,
So I dug into this further. There are a couple of problems that we need to sort out in the API:
- The createdBy, updatedBy, dateModified, dateCreated fields should never be modified directly. Personally, I would like to see them completely ignored, but I need to dig into our Swagger Defs and Swagger SDK generation process and see if we can tell the process to ignore them on the input object.
- In the meantime I would just do what you do in the second example where you manually set the properties you want in a new object instance. Make sure you create a QueueRequest object and then copy over all the fields over. (e.g. the media setting values, etc...)
updateQueue = PureCloudPlatformClientV2.QueueRequest()
updateQueue.id=retrieved_queue.id
updateQueue.name='Chat2'
.... Copy all of the rest of the fields
This might take a little time to fix because unfortunately, the long-term solution might span a couple of teams.
Thanks for your feedback on this and we will look further into this.
Manager, Developer Engagement
system | 2020-11-26 19:12:30 UTC | #5
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: 9154