Has anyone used SWQL or SQL to update a Bearer Token value for an API Poller?

We have a token that we renew on a regular basis.  When we have monthly patching and reboots of systems, the token is expiring during this process.  I created a .bat file that can generate a new token and I can parse it out to get the new token.  I would like to store it in the existing Bearer Token, or create a new one and update the token being used by the 5 other API Pollers that are using the same Bearer Token.  Any ideas on how to update this information with a script?

  • The newer versions (starting in 2022.4) of the platform include some new credential management.

    Entity: Orion.Credential


    CreateCredentials Creates credential with provided list of properties
    CreateSNMPCredentials Creates SNMP v1 or v2c credentials
    CreateSNMPv3Credentials Creates SNMP v3 credentials
    CreateUsernamePasswordCredentials Creates credentials with username and password, these are used for example by WMI polling.
    CreateUsernamePasswordWithContentCredentials Creates credentials with username, password and content, these are used for example by PaloAlto REST polling.
    UpdateCredentials Updates credential properties
    UpdateSNMPCredentials Updates SNMP v1 or v2c credentials.
    UpdateSNMPv3Credentials Updates SNMPv3 credentials.
    UpdateUsernamePasswordCredentials Updates credentials with username and password. These are used, for example, by WMI polling.
    UpdateUsernamePasswordWithContentCredentials Updates credentials with username, password and content. These are used for example by PaloAlto REST polling.

    You could look in the credential entity for the API Poller creds you are trying to update and then use the UpdateCredentials verb.

  • This is great to hear!  We are going to be upgrading from 2020.2.6 to a newer release in August.  I will definately investigate this option after the upgrade.

  • I've got this working within the api poller, and fully outside of the api poller, doing it both inside and outside an api poller sounds really hard. I know one way you could do it, but it comes with hefty limitations.

    This stuff's easier to chat about imo, feel free to drop a message

  • What is the proper format to pass in the properties? What are the specific key and values needed in the XML?

  • Are you referring to a SWIS verb or whatever query the bearer token is used for?

  • Orion.Credential UpdateCredentials (int id, Dictionary<string, string> properties)

    The SWIS verb. I cannot get the second paramater of the function to pass correctly without it throwing an error. I looked at Credential Management · solarwinds/OrionSDK Wiki · GitHub, for what keys it requires. When i formatted it like this as an xml doc first, it threw some sort of error for  not having an "add" function which made me think it indeed does want it as a dictionary. But everytime i tried pass a dictionary it told me it was the incorrect format.
    How am i supposed to pass the xml string in a dictionary format?

    If you got it working, can you show me an example format?

  • #Documentation: https://github.com/solarwinds/OrionSDK/wiki/Credential-Management
    # Connect to the SolarWinds server
    $hostname = ""
    $username = ""
    $password = ""
    $swis = Connect-Swis -Soap12 https://$hostname/swvm/services/InformationService -Username $username -Password $password -IgnoreSslErrors
    $bearer_token_credset = ""
    $bearer_token_desc = ""
    $bearer_token = ""
    $properties = [System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]]::new()
    $properties.Add("Name", $bearer_token_credset);
    $properties.Add("Description", $bearer_token_desc);
    $properties.Add("Token", $bearer_token);
    # Define the parameters for the UpdateCredential function
    $CredentialID = 201
    # Call the UpdateCredential function
    Invoke-SwisVerb $swis Orion.Credential UpdateCredentials @($CredentialID, $properties)

    This is the error I'm getting:

  • You may be able to skip this step by generating the bearer in a login step, then turning it into a variable for reuse within the API poller, however if this method is the required one, I'll take a look when I can, Got some UTF8 code in PS laying around. The SWQL studio expanded api field should have a description of the format required

  • Looks like it wants an input of [in32]ID, @(props) rather than @(id, props)

  • Updated description with 

    1) get URI:
    SELECT c.Uri FROM Orion.Credential c where id = target

    2) inspect
    $cred = Get-SwisObject -Uri $uri -SwisConnection $swis

    3) set

    $props = @{description = 'test'}

    Set-SwisObject -Uri $uri -Properties $props -SwisConnection $swis