Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Logging into Vault using API

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Eli_Dexter
1259 Views, 15 Replies

Logging into Vault using API

I am trying to Log0in into Vault using API within PowerShell. Here is my code:

[System.Reflection.Assembly]::LoadFrom('C:\Program Files\Autodesk\Autodesk Vault 2024 SDK\bin\x64\Autodesk.Connectivity.WebServices.dll')
$serverID = New-Object Autodesk.Connectivity.WebServices.ServerIdentities
$serverID.DataServer = "<server name>"
$serverID.FileServer = "<server name>"
$VaultName = "Vault"
$UserName = "<UserName>"
$password = "<Password>""
$licenseAgent = [Autodesk.Connectivity.WebServices.LicensingAgent]::Client
$cred = New-Object Autodesk.Connectivity.WebServicesTools.UserPasswordCredentials($serverID, $VaultName, $UserName, $password, $licenseAgent)
$vault = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager($cred)

 

Last line causes an error:

New-Object : Exception calling ".ctor" with "1" argument(s): "The type initializer for 'Autodesk.Connectivity.WebServicesTools.WebServiceManager' threw an exception."
At G:\Software\SSDI\Vault\Temp\Test.ps1:11 char:12
+ $vault = New-Object Autodesk.Connectivity.WebServicesTools.WebServi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

I cannot find any help with this error. Any suggestion why this happens?

 

Labels (1)
15 REPLIES 15
Message 2 of 16
Eli_Dexter
in reply to: Eli_Dexter

I did copied AdskLicensingSDK_7.dll to PowerShell folder C:\Windows\System32\WindowsPowerShell\v1.0
That had no effect...
Message 3 of 16
Markus.Koechl
in reply to: Eli_Dexter

v7 licensing (Vault 2024) requires to copy 3 files to the execution folder. I updated the PowerShell template accordingly:

# NOTE - click licensing v7 requires to copy AdskLicensingSDK_7.dll, AdskIdentitySDK.config, and AdskIdentitySDK.dll to PowerShell execution folder C:\Windows\System32\WindowsPowerShell\v1.0 before Powershell runtime starts

I reproduced your error removing the additional required files and re-established the connection adding and restarting the PowerShell terminal.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 4 of 16
Eli_Dexter
in reply to: Markus.Koechl

I have dropped the other 2 files and even (just in case) all other Autodesk.*.DLL files from C:\Program Files\Autodesk\Autodesk Vault 2024 SDK\bin\x64 folder to the PowerShell folder and still having same error...

Here is a screenshop of my PowerSell folder:

Eli_Dexter_0-1699464145797.png

 

Message 5 of 16
Markus.Koechl
in reply to: Eli_Dexter

Did you ensure that you are logged in to your Autodesk Account?


Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 6 of 16
Eli_Dexter
in reply to: Markus.Koechl

I am running Vault, so I am looged in into Autodesk Account. Also, I am talking to you in this Forum, so I am logged in into my account...

Message 7 of 16
Markus.Koechl
in reply to: Eli_Dexter

Re-reading the error you provided (type initializer) you might have to cast the $vault variable like this: [Autodesk.Connectivity.WebServicesTools.WebServiceManager]$vault = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager($cred)


Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 8 of 16
Eli_Dexter
in reply to: Markus.Koechl

Sorry, that was not it either. Adding that cast or removing $Vault =  completely still produces the same error...

I have a suspition that it has something to do with $Cred variable. This is the value of my $cred variable:

RequiresClientLicense : True
UserName : Eli_Admin
ReadOnly : False
RequiresSignIn : True
RequiresSignOut : True
SupportsSignIn : True
SupportsSignOut : True
ServerIdentities : Autodesk.Connectivity.WebServices.ServerIdentities
Session :
VaultName : Vault
WindowsAuthenticationNonDefaultCredentials :

Message 9 of 16
jbetz42
in reply to: Eli_Dexter

Did you manage to connect to Vault using Powershell? I have only found these two ressources but according to this thread they are already outdated as the licensing part has changed:

 

I wonder why nobody at Autodesk sees the need for a good public API documentation along with examples. All documentation is fragmented, hidden in a non-public CHM file that requires a Vault and SDK installation first. Reading through multiple threads in this forum this issue is persistent over years and not adressed.

 

The Inventor guys handle their documentation way better incl. samples and a nice public API reference.

Message 10 of 16
Eli_Dexter
in reply to: jbetz42

I has never been resolved. I have just wend around the issue...

Message 11 of 16
Markus.Koechl
in reply to: jbetz42

Hello @jbetz42. We regret seeing your frustration. I acknowledge that we should enhance the accessibility of documentation and samples and best aggregate federated sources. As a first step, I recently posted a series of articles targeting this on the official Autodesk PDM|PLM Blog, tagged with Vault Customization. Now, you might shout at me to start another location to search for information about Vault programming. Yes and no - yes, it is a new link. No - it matches the overall Autodesk documentation scheme, which has product documentation, a knowledge base, community forums, and an Autodesk-hosted blog for all major products. 

Back to your request for an updated template to login to Vault using Powershell: this article should provide you with the required information on what you need to change for each Vault release: 

MarkusKoechl_0-1712161983432.png

I uploaded my 2024 PowerShell template for reference. The comment in line #15 matches the requirements listed before: 

MarkusKoechl_2-1712162255981.png

With that, I dare to say that logging into Vault using Powershell has been resolved. I hope you can agree by leveraging the updated template (don't forget to remove the security block after downloading the zip; otherwise, the script will not execute).



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 12 of 16
jbetz42
in reply to: Markus.Koechl

Thank you @Markus.Koechl for providing an updated example code and all the useful resources. I will not shout at you. I promise. ✌️

 

May I ask you one more thing regarding the Vault API? I have recently learned that Vault basically uses a SOAP API. In this forum multiple requests exist to connect to Vault besides the provided C# examples e.g. in JavaScript or Python:

 

Is there any Python example code in existence to connect to Vault?

Message 13 of 16
Markus.Koechl
in reply to: jbetz42

I don't have Java or Phyton sample code. SOAP is the underlying web service communication, but the Vault API adds much more than that. Think about client extensibility, or especially the Job Service API. So far, our API has targeted the NET Framework for the full scope. The latest Vault API 2025 (released last week) adds .NET Core as a first step in achieving broader platform independence. So, you see, we are on a journey and expect more to come in the near future.


Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 14 of 16
jbetz42
in reply to: Markus.Koechl

Thank you @Markus.Koechl for the updated Powershell example. I managed to get it to work reading useful data from the AdminService. I have one more question regarding Properties in Vault:

 

Let's say I have a Property called "Manufactuer_name" that contains a list of manufacturers. How can I read the list of all values from this property in PowerShell?

list-value.png

I basically need a function that requires the property name as input parameter and returns a list of all possible values for the given property. Can you give me a hint on how to achieve this?

 

Message 15 of 16
Markus.Koechl
in reply to: Eli_Dexter

@jbetz42: Please mark this thread as resolved and start a new one, as you asked a new question. I will answer the new one. Thanks.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 16 of 16
jbetz42
in reply to: Markus.Koechl

Thank you for your quick reply @Markus.Koechl . I am not the originator of the post therefore I cannot mark your provided solution as solved. @Eli_Dexter I can confirm that the provided code works on Vault 2024 so maybe you can mark this post as solved?

As requested I have opened another post: https://forums.autodesk.com/t5/vault-customization/reading-list-values-of-a-property-in-vault-using-...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report