Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
New Member

Renaming a document file using REST API

We have been able to upload and move files successfully using the REST API but we are having issues with the "Modify File" function in order to rename a file.


Here is the example from the developer guide:

cisco1.gif

Here is our script (some part of the filename has been erased for security):

cisco2.gif

We recieve a 500 internal server error.

cisco3.gif

Any ideas would be greatly appreciated, this is our final step to be able to create our workflow.

Everyone's tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Renaming a script file using REST API

I got this working from within a UCCX script as I do not have familiarity with a REST client at this time.  I shall look into it.

Without further ado...

The lessons learned

  1. Your URI needs to have the full path to the filename.  E.g., http://1.1.1.1/adminapi/document/en/somefolder/somefile.xml
  2. The declaration in your input is optional.*
  3. The name space and schema attr in your input are optional.*
  4. The value does not have to end with a trailing slash, that's optional.*  E.g., /en/ or /en
  5. The value does not have to be absolute, it can be relative.*  E.g., /en or en

*For Content-Type: application/xml only.

Recommended actions for you

  1. Your URI needs to contain the filename, not just the language folder
  2. Your needs to contain the language folder

The file I am trying to rename

uccx-api-rename-original.png

The script I am using

Variables

String[] rest = new String[] {"http:///adminapi/document/", "", "", "application/xml", "", "", "", ""}

Script

Start

Set rest[0] = rest[0] + "en/original.txt"

Set rest[4] = (String) TEXT[/en/original.txtnew.txt]

Make REST  Call

     Successful

          /* Add Comment */

     Unsuccessful

          /* Add Comment */

End

EDIT: I see that it's not obvious why I created a TEXT document literal and then cast it to a string.  Allow me to explain.  When you have the XML delcaration which contains two double-quoted attributes, or worse, a huge XML document that contains 30 or 40 double-quotes, you need to go and escape every one of them in your String literal.  E.g., attr=\"value\"  By using the method I have used, you can paste in your XML without having to escape any quotes.  It's just easier.  In my opinion.

An example showing the difference (albeit a small difference):

Set my_string = U"value"

Set my_string = (String) TEXT[value]

More details on Make REST Call

uccx-api-rename-make-rest-call.png

Active debugging results

uccx-api-rename-active-debug.png

The file renamed

uccx-api-rename-new.png

Rest client

EDIT: I found a Firefox plugin REST Client and it worked from there as well.

uccx-api-rename-rest-client.png

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
9 REPLIES

Renaming a script file using REST API

Try putting the absolute path to the XSD in the namespace in your request. Also, trim out the whitespace in your request.

Tanner Ezell
www.ctilogic.com

Tanner Ezell www.ctilogic.com
New Member

Renaming a script file using REST API

I got the same error when I used the absolute path like this:

xsi:noNamespaceSchemaLocation="http://192.168.42.1/adminapi/src/main/resources/xsd/Files.xsd"

Can you clarify on what you mean when you say clear out the whitespace?

Renaming a script file using REST API

If I'm not mistaken you are mixing the script API with th Document API.  Otherwise, why are you referencing an XML file when talking about renaming a script?

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Renaming a script file using REST API

You are correct, it is the document API and I am trying to rename a document in the /document/en_US folder.

Here is a screenshot of my REST client configuration:

cisco4.gif

Re: Renaming a script file using REST API

I got this working from within a UCCX script as I do not have familiarity with a REST client at this time.  I shall look into it.

Without further ado...

The lessons learned

  1. Your URI needs to have the full path to the filename.  E.g., http://1.1.1.1/adminapi/document/en/somefolder/somefile.xml
  2. The declaration in your input is optional.*
  3. The name space and schema attr in your input are optional.*
  4. The value does not have to end with a trailing slash, that's optional.*  E.g., /en/ or /en
  5. The value does not have to be absolute, it can be relative.*  E.g., /en or en

*For Content-Type: application/xml only.

Recommended actions for you

  1. Your URI needs to contain the filename, not just the language folder
  2. Your needs to contain the language folder

The file I am trying to rename

uccx-api-rename-original.png

The script I am using

Variables

String[] rest = new String[] {"http:///adminapi/document/", "", "", "application/xml", "", "", "", ""}

Script

Start

Set rest[0] = rest[0] + "en/original.txt"

Set rest[4] = (String) TEXT[/en/original.txtnew.txt]

Make REST  Call

     Successful

          /* Add Comment */

     Unsuccessful

          /* Add Comment */

End

EDIT: I see that it's not obvious why I created a TEXT document literal and then cast it to a string.  Allow me to explain.  When you have the XML delcaration which contains two double-quoted attributes, or worse, a huge XML document that contains 30 or 40 double-quotes, you need to go and escape every one of them in your String literal.  E.g., attr=\"value\"  By using the method I have used, you can paste in your XML without having to escape any quotes.  It's just easier.  In my opinion.

An example showing the difference (albeit a small difference):

Set my_string = U"value"

Set my_string = (String) TEXT[value]

More details on Make REST Call

uccx-api-rename-make-rest-call.png

Active debugging results

uccx-api-rename-active-debug.png

The file renamed

uccx-api-rename-new.png

Rest client

EDIT: I found a Firefox plugin REST Client and it worked from there as well.

uccx-api-rename-rest-client.png

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Renaming a document file using REST API

Bravo, Anthony..

Renaming a document file using REST API

Thanks!

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
New Member

Re: Renaming a script file using REST API

Using the filename in the URI did the trick!

Thank You.

Re: Renaming a script file using REST API

Awesome.  You're welcome.  I saw you posted over on: https://communities.cisco.com/thread/41129 as well.  I'm going to try to be more active over there because I see great things on the horizon with the Admin API.  See you around.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
792
Views
10
Helpful
9
Replies
CreatePlease to create content