Hello,
I'm trying to import new schedules on the platform using python's requests module to make API calls using a Client Credentials grant. I've tried two approches :
-
Using the import workflow :
making a post request api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/import/uploadurl
then making a put request to the upload url and finally making post request to api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/import -
Using the schedule update workflow :
First generating a blank schedule by making a post request to /api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules
Then a post request to /api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/{new_schedule_id}/update/uploadurl
a put request with the planning to the upload url and finally a post request to /api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/{new_schedule_id}/update
I actually only get 200 responses and I manage to create a blank schedule, however when making the final request to process the uploaded schedule, no schedule is imported or is updated depending on the workflow. Furthermore when I do a get request on api v2 contentmanagement status no processes are listed. Has anyone encountered a similar problem knows how to solve it ?
Here is a detail of my requests on the schedule update workflow :
Blank request schedule :
requestHeaders = {
"Content-Type": "application/json",
"Authorization": f"{ token_type } { access_token }"
}
weekId = f"2022-05-16"
blank_schedule_json={
"description": PLANNING_DESCRIPTION,
"weekCount": 1
}
response = requests.post(f"api.{ENVIRONMENT}/api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules", headers=requestHeaders, json=blank_schedule_json)
Status code : 201
Update upload url :
requestHeaders = {
"Content-Type": "application/json",
"Authorization": f"{ token_type } { access_token }"
}
schedule_size_json={
"contentLengthBytes": byte_size
}
response = requests.post(f"api.{ENVIRONMENT}/api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/{new_schedule_id}/update/uploadurl", headers=requestHeaders, json=schedule_size_json)
response : {'uploadKey': 'userUploads/schedule/import/xxx.input.json.gz', 'url': 'https://fileupload.mypurecloud.de/userUploads/schedule/import/...', 'headers': {'Content-Encoding': 'gzip', 'Content-Type': 'application/json', 'x-amz-tagging': 'organizationId=xxx-xxx-xxx-xxx&originPlatform=PureCloud&role=darth&owner=Dev-CloudAppsDarth@genesys.com'}}
status code : 201
Schedule file upload :
test_dict = {
"metadata":{
"version":1
},
"agentSchedules":[
{
"userId":"xxx-xxx-xxx-xxx-xxx",
"shifts":[
{
"activities":[
{
"activityCodeId":"xxx- xxx-xxx-xxx-xxx",
"startDate":"2022-05-16T12:00:00.000Z",
"lengthMinutes":120,
"description":"",
"paid":True
}
],
"manuallyEdited":True
}
],
"fullDayTimeOffMarkers":[
],
"metadata":{
"version":1
}
}
]
}
jsonfilename = 'data/plannings/test.json.gz'
json_str = json.dumps(test_dict) + "\n"
json_bytes = json_str.encode('utf-8')
with gzip.open(jsonfilename, 'w') as fout:
fout.write(json_bytes)
byte_size = os.path.getsize(jsonfilename)
requestHeaders = {
'Content-Encoding': 'gzip',
'Content-Type': 'application/json',
'x-amz-tagging': 'organizationId=xxx-xxx-xxx-xxx&originPlatform=PureCloud&role=darth&owner=Dev-CloudAppsDarth@genesys.com',
'Content-Type': "application/json"
}
response = requests.put(upload_url, headers=requestHeaders, data=open(jsonfilename, 'rb'))
Status code : 200 - OK
response : {'Content-Length': '0', 'Connection': 'keep-alive', 'Date': 'Tue, 26 Apr 2022 14:32:17 GMT', 'x-amz-expiration': 'expiry-date="Wed, 04 May 2022 00:00:00 GMT", rule-id="wfmService-ScheduleImport"', 'x-amz-server-side-encryption': 'AES256', 'ETag': '"31fb352482b6515ceb253b4197c3e713"', 'Server': 'AmazonS3', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 d32d70ba49809b2292cca689969507a0.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'LHR50-P1', 'X-Amz-Cf-Id': 'bPgpD3PaGM3Rnao1rp7dw3PBKwKASxooQtmIIN3N-MvhOH5Oelv40A=='}
Update processing call :
requestHeaders = {
"Content-Type": "application/json",
"Authorization": f"{ token_type } { access_token }"
}
update_json = {
"uploadKey": upload_id,
}
response = requests.post(f"api.{ENVIRONMENT}/api/v2/workforcemanagement/businessunits/{bu_id}/weeks/{weekId}/schedules/{new_schedule_id}/update", headers=requestHeaders, json=update_json)
I hope I made an obvious mistake that can be fixed easily, or someone encountered a similar problem !
Best regards,
Maxime