Help me Jeremy Tammik! or anyone else familiar with REST API calls to Revit Svr

Help me Jeremy Tammik! or anyone else familiar with REST API calls to Revit Svr

ted_kovacs
Contributor Contributor
2,194 Views
15 Replies
Message 1 of 16

Help me Jeremy Tammik! or anyone else familiar with REST API calls to Revit Svr

ted_kovacs
Contributor
Contributor

I hope I posted this in the right place...

 

Using bits and pieces I found on the web along with some original coding, I put together a script that enumerates all of the projects on Revit Server using a REST API call to a Revit host server, and then automates running Autodesk's command line RevitServerTools utility to update an accelerator's cache.  I have been using it on Revit Server 2015 with great success.  However, the same script refuses to work on Revit Server 2016, and I can't figure out why.

 

I narrowed it down to the function below that handles the REST request, and found that it is not returning anything, just zero length string.  Does the 2016 URL need to be formatted differently?  Some other problem?  The complete script is attached if it helps or if anyone is interested.

 

 Function GetContents(Folder)
 Dim restReq
 Dim url
 Dim userName
 Dim userMachine
 Dim GUID
 Dim outData
 Set restReq = CreateObject ("Microsoft.XMLHTTP")
 'Create the headers that we will need to make the request
 If Folder = "" Then
  url = "http://" & RevitServerHostName & "/RevitServerAdminRESTService" & RevitServerVersion & "/AdminRESTService.svc/ /Contents"
 Else
  url = "http://" & RevitServerHostName & "/RevitServerAdminRESTService" & RevitServerVersion & "/AdminRESTService.svc/" & Folder & "/Contents"
 End If
 restReq.open "GET", url, False
 restReq.setRequestHeader "User-Name", strUserName
 restReq.setRequestHeader "User-Machine-Name", strComputerName
 restReq.setRequestHeader "Operation-GUID", GetGuid() 
 restReq.send("")
 GetContents = restReq.responseText

 End Function

 

Thanks in advance for any help provided!

 

Ted

0 Likes
Accepted solutions (1)
2,195 Views
15 Replies
Replies (15)
Message 2 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

Thank you for your query.

 

Yes, sure, this seems to me to be the right place.

 

I am checking with the development team to see whether they are aware of any changes.

 

I looked at your script, but it is much too convoluted for me to actually see what string you are using to access the Revit Server data.

 

Could you provide that in isolation, please, to make it easier to understand?

 

Have you looked at these examples on The Building Coder demonstrating various aspects of programmatically accessing Revit Server?

 

http://thebuildingcoder.typepad.com/blog/2013/08/revit-server-api-access-and-vbscript.html#3

 

http://thebuildingcoder.typepad.com/blog/2013/12/saving-a-new-central-file-to-revit-server.html

 

http://thebuildingcoder.typepad.com/blog/2014/01/rest-post-request-to-revit-server-2014.html

 

http://thebuildingcoder.typepad.com/blog/2014/08/accessing-a-revit-server-central-model-path.html

 

The last one may very well have to do directly with your problem.

 

I hope this helps.

 

Happy weekend!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 16

ted_kovacs
Contributor
Contributor

Thanks Jeremy.   The string I am using to access the Revit Server data is, depending on the server version, is one of the following.

 

For 2015:

http://RevitHost/RevitServerAdminRESTService2015/AdminRESTService.svc/ /Contents

 

For 2016:

http://RevitHost/RevitServerAdminRESTService2016/AdminRESTService.svc/ /Contents

 

The only difference in that function when run for 2015 versus 2016 is the year itself in the URL.  Yet, it works for 2015 and not for 2016.

 

I looked through the links you provided, and most of those I had already found.  Your first link has a proof of concept VB script where the function I am now having a problem with was used almost verbatim with only small changes to take it from proof of concept to something usable for my purposes. Several of the links you provided were indeed helpful back when I originally put the script together, but unfortunately don't seem to give me any clues as to why it doesn't work on 2016. 

 

I'm sorry if you found my script convoluted.  I included only the one function at issue in my original post in order to make it less necessary to digest the entire script.  I am not really a programmer, and I did the best I could.  I was pleased with the result for my needs other than perhaps my method of dealing with a JSON response being pretty much a total hack (yet one that works). 

 

If you prefer, ignore my script entirely, and test the proof of concept vbscript in your first link on a 2016 Revit server.  I believe it will have the same issue of returning only a blank response just like the function in my script does. 

 

I appreciate your efforts to help.  Also, I didn't realize pressing "need an answer" would generate a new case.  My apologies for that.

 

Ted

0 Likes
Message 4 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

Thank you for your update and feedback.

 

No problem at all!

 

I hope I will hear back from the developemnt team soon, and will let you know as soon as I do.

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted, 

 

No reply from them yet, but then it is still early in the week and in the day too, in the US...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 16

ted_kovacs
Contributor
Contributor

I am patiently waiting, but still hoping the development team will respond to you soon.

 

Thanks,

 

Ted

0 Likes
Message 7 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted, 

 

Sorry, I have not yet received any response.

 

I re-prompted them now.and am keeping my fingers crossed for you.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted, 

 

I heard back from the development team now. They say:

 

"I took a quick look at this. I couldn’t get it to work even on 2015, so I think there must be some small syntactical difference between the URL listed in the email and the actual URL he uses (e.g. why the apparent space preceding “/Content”?). Could you have him just send the actual URL string he’s using that’s successful in 2015 and not successful in 2016?"

 

Notice how similar this is to my very first reponse to you?

 

The code you provide is rather convoluted and does not make the real problem sufficiently clear.

 

Can you please just send the URL that your code produces and that works for Revit Server 2015 and fails for Revit Server 2016?

 

Hopefully that will enable us to isolate and identify the problem.

 

Thank you.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 16

ted_kovacs
Contributor
Contributor

Jeremy,

 

I would point out that my original reply to your first post included the information you are once again requesting.  Since that reply did not get us where we need to be to solve this, I will attempt to restate and clarify below.


For 2015, the (working) URL is "http://RevitHost/RevitServerAdminRESTService2015/A​dminRESTService.svc/ /Contents" (which intentionally includes a space)


For 2016, the (not working) URL is the same, only the "2015" part is changed to "2016".

 

 

The URL above is used for getting the contents of the root of the Revit server.  Your developer asked "why the apparent space preceding '/Content"".  The space is what you use when you need the contents of the root rather than the contents of a folder, or so I understand.  Here is the foundation for that belief.


1.   A space is used in the example that you linked to here http://thebuildingcoder.typepad.com/blog/2013/08/revit-server-api-access-and-vbscript.html#3

2.   I found other references on the web suggesting a space was needed in order to get the contents from the root

3.   When I used a space in my code to get the root contents on a 2015 server, it works, and I cannot get it to work without the space.

 

 

This is not the only URL I use.  After I get the contents of the root, I recursively get the contents of each and every folder and subfolder in order to enumerate all the the models contained in every folder on the Revit server.  That second URL *does* in fact still work on 2016. It is the same URL as above, only the single space before "/Contents" is replaced with the name of a specific folder.  For a 2016 server, the URL would be something like... "http://RevitHost/RevitServerAdminRESTService2016/A​dminRESTService.svc/MyFolder/Contents".

 

 

With this in mind, I would restate my question as "What URL are you supposed to use to get the contents of the root of a 2016 Revit Server?".  I need the contents of the root in order to know what folder names to use the second URL on, as these folders are added, removed, and renamed over time so I cannot hard code them. 

 

 

Thanks,

 

 

Ted

0 Likes
Message 10 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

That is decidedly weird.

 

Please try it without the space, preferably by simply deleting it, or, if need be, by replacing it with an underscore or something.

 

I am not aware of any of the conventions you refer to, and I am aware of heaps of problems caused by spaces in file paths.

 

The fact that it works with a space in 2015 is strange, and it could very well be the reason it fails in 2016.

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 11 of 16

ted_kovacs
Contributor
Contributor

Jeremy,

 

I tested a number of altered URLs on 2015 and 2016.  To avoid listing every URL twice when I am referring to results from both 2015 and 2016, please note that while I am listing only the 2015 URLs I used, I did replace the "2015" part with "2016" when running it against a 2016 Revit server.

 

On Revit Server 2015, using a URL with the space ("http://RevitHost/RevitServerAdminRESTService2015/​A​dminRESTService.svc/ /Contents") I get the following expected response showing the folder names I need.  Whereas using that URL on 2016 returns only a blank string.

 

{"Path":" ","DriveFreeSpace":43532005376,"DriveSpace":128479911936,"Files":[{"IsText":false,"Name":"ModelLocationTable.db3","Size":20480},{"IsText":false,"Name":"ModelLocationTable.db3-journal","Size":12896},{"IsText":true,"Name":"super.lock","Size":69}],"Folders":[{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"00_Prospects","Size":23955955},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"01_Design Development","Size":23912193},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"02_Jobs","Size":1477916658},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"03_Completed Jobs","Size":290260866},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"08_Standards","Size":23413224},{"HasContents":true,"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"09_Internal","Size":86779847},{"HasContents":true,"LockC
ontext":null,"LockState":0,"ModelLocksInProgress":null,"Name":"XX_EOL","Size":86955491}],"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Models":[]}

 

On both a Revit 2015 and 2016 server, If I take the space out of the URL like this...

"http://RevitHost/RevitServerAdminRESTService2015/​A​dminRESTService.svc//Contents"

Or removing the space AND reducing the double slashes to just one, like this...

"http://RevitHost/RevitServerAdminRESTService2015/​A​dminRESTService.svc/Contents")

I get this response...

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Service</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight:
bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Service</p>
      <p>Method not allowed.</p>
    </div>
  </body>
</html>

 

On both a Revit 2015 and 2016 server, if I replace the space with an underscore ("http://RevitHost/RevitServerAdminRESTService2015/​A​dminRESTService.svc/_/Contents") , I get back a response in the right format, but no folder names.  Like this response...

 

{"Path":"_","DriveFreeSpace":43878522880,"DriveSpace":128479911936,"Files":[],"Folders":[],"LockContext":null,"LockState":0,"ModelLocksInProgress":null,"Models":[]}

 

I know on the web, spaces often need to be replaced with a "%20", so I tried that too.  ("http://RevitHost/RevitServerAdminRESTService2015/AdminRESTService.svc/%20/Contents").  On 2015, I get the right format, with no folders, just like using an underscore.  However, on 2016, I get a blank response again.

 

Are there any other alternate URLs you think would be worth trying?

 

Thanks,

 

Ted

0 Likes
Message 12 of 16

ted_kovacs
Contributor
Contributor
Accepted solution

Jeremy,

 

You can stop looking into this issue.  I found the solution.  You were on the right track though, even though that didn't ultimately help me find the solution any sooner.  Whille having a space in the URL worked fine in 2015 and not on 2016, replacing the space with a pike "|" symbol works on both versions.  I found the answer within the Revit 2016 SDK, which includes a Revit Viewer example written in C++.  

 

This is the working 2016 URL to get the contents of the root
http://RevitHost/RevitServerAdminRESTService2016​/​A​dminRESTService.svc/|/contents

 

I genuinely do appreciate your time and effort to help solve this.  However, at the same time, I did not appreciate what I perceived to be hints of condescension masked with pleasantries within your replies. Perhaps I am reading more into it then was there... but I doubt it.  It seemed pretty clear to me. I'm sure you are a smart guy Jeremy, and are much more knowledgeable on certain select topics than I, but it would serve you well to check your ego at the door when helping the paying customers of the company you work for. You've taken what could have been a positive interaction with Autodesk, and made it much less so.  You may not have crossed any major lines, but I'd still call that a loss for the day on behalf of your employer.

 

Ted

 

 

 

0 Likes
Message 13 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

Congratulations on solving the problem!

 

Thank you for confirming.

 

Sorry for the perceived condescension... it was an extremely busy week for me, and I squeezed this in too hard.

 

Please accept my apologies.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 14 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

I finally bit the bullet and RTFM myself.

 

In this case, the place to look is the Revit Server REST API documentation in the PDF file named named 'Revit Server REST API Reference.pdf' in the Revit SDK 'Revit Server SDK' subfolder.

 

It clearly states:

 

Since slashes '\' and backslashes '/' are URL special characters, object paths are formatted as:

 

  • Server root: '|'
  • Folder Path: 'folderName1[|folderName2[...]]'
  • Model Path: '[folderName1[|folderName2[...]|]]modelName.rvt'

 

I hope this helps.

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 15 of 16

ted_kovacs
Contributor
Contributor

Jeremy,

 

Thank you for that information, and for your prior reply as well.

 

Ted

0 Likes
Message 16 of 16

jeremytammik
Autodesk
Autodesk

Dear Ted,

 

Thank you for your appreciation.

 

I published a summary of our discussion on The Building Coder for better readability and future reference:

 

http://thebuildingcoder.typepad.com/blog/2016/03/pi-day-meeting-ski-tours-and-revit-server-bar-separ...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes