cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
Please note that Remote Expert Mobile announced end-of-life and support will end on February 28, 2022.
1340
Views
1
Helpful
5
Replies
Highlighted
Beginner

Changing Greetings through CUPI with Python

Hi all,

I am trying to update the call handler holiday greetings through the CUPI API.

The environment is unity 8.6, but will soon be migrating to 10.5/6 not sure yet.

I am using the python requests library to perform the request with little success.

The issue that I am having is that no matter the combination of headers etc I have tried I keep getting an error;

- 415 - Unsupported Media Type

Here is my code sample;

import requests

headers = {'Content-type': 'audio/wav', 'Connection': 'keep-alive'}

wave_file = open('/path/to/holiday.wav', 'rb').read()

url = 'https://tstcuc86/vmrest/handlers/callhandlers/6f9356a0-93f2-4b34-832a-b0bd3410a57d/greetings/Holiday/greetingstreamfiles/1033/'

payload = [('StreamFile', ('holiday.wav', wave_file))]

r = requests.put(url,

            auth=('admin', 'p@ss'),

            headers=headers,

            files=payload,

            verify=False

            )

Has anyone had any success with updating greetings with python ?

If so can you show me a working code snippet  please ?

Thanks in advance.

Brad

1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

Re: Changing Greetings through CUPI with Python

Here it is:

https://github.com/bobthebutcher/cupi/blob/master/cake.py

I am still working on some methods and documentation. Hopefully it can save someone some cycles.

View solution in original post

5 REPLIES 5
Cisco Employee

Re: Changing Greetings through CUPI with Python

that error would have less to do with your HTTP headers and such and the WAV file itself - Connection can be fussy about the format which is why all my tools that do anything with greetings/voice names ship with a SoX library to do WAV file conversions - what's the format of your WAV file - I always force pcm:8000,16,1 before uploading. 

Beginner

Re: Changing Greetings through CUPI with Python

Thanks @lindborg, (bit lat to reply here, sorry about that) I am certain that is not the issue as I am using a recording that I downloaded for unity and is currently being used. I have in the mean time got this working. I will post a link later on to a python module I am building which has a method for updating greetings

Beginner

Re: Changing Greetings through CUPI with Python

Here it is:

https://github.com/bobthebutcher/cupi/blob/master/cake.py

I am still working on some methods and documentation. Hopefully it can save someone some cycles.

View solution in original post

Beginner

Re: Changing Greetings through CUPI with Python

I am working on a project where I need to upload wav files into Standard greeting. I am a little new to python and not the greatest. I like what Bradley did with cake.py but way out of my knowledge base currently to follow. Would it be possible if you can post the working script from the one above? That one seemed simple and something that I was able to follow but I am not smart enough to figure what is breaking the upload. I am also getting 415 error in the upload. thank you

Beginner

Re: Changing Greetings through CUPI with Python

@I have figured it out. I found that the documentation for 8.x and newer states there is a new method for uploading wav files using a single url instead of the old 3 step method. however, the 3 step methods url is not defined in the scheme and that may because there is no option for them. So, i though that old 3 step was not supported on 11.5. I found that new method did not work no matter what i tried but the legacy 3 step method work perfectly. here is my code snippet for you to enjoy.

        ###########

        ##1 Create Temp Voice file

        ###########

        #URL to create tempary file on unity connection

        url = "https://" + cucUnity + "/vmrest/voicefiles"

     

        #POST request that build temp file

        r = requests.post(url, auth=HTTPBasicAuth('######', '######'))

     

        #Store temp file in varible

        temp_file = r.text

 

        ###########

        ##2 Copy WAV data into Temp Voice file

        ###########

        #URL to upload WAV data to tempary file

        url = "https://" + cucUnity + "/vmrest/voicefiles/" + temp_file

     

        #header needed for REST API request

        headers = {

            'Content-Type': "audio/wav"

        }

 

        #Open file and upload via REST API request to

        with open(wav_file_path, 'rb') as store_wav_file:

            r = requests.put(url, auth=HTTPBasicAuth('######', '######'), headers=headers, data=store_wav_file)

            print (r)

 

        ###########

        ##3 Set WAV file into greeting Voice file

        ###########

        #URL to set temp file in Unity to Call Handler Greeting

        url = "https://" + cucUnity + "/vmrest/handlers/callhandlers/" + callhandler_id + "/greetings/Standard/greetingstreamfiles/1033/"

     

        #header to needer to perform in json

        headers = {

            'Content-Type': "application/json",

            'Connection': 'keep_alive'

        }

     

        #set StreamFile option per schema with the temp file name. file is stored in Unity Connection

        payload = {

            'StreamFile': temp_file

        }

        #REST API request

        r = requests.put(url, auth=HTTPBasicAuth('######', '######'), headers=headers,  data=json.dumps(payload))

        print (r)

CreatePlease to create content
Content for Community-Ad
FusionCharts will render here