This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

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?

Parents Reply Children
  • 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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, 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

  •   
    Updating the way Chanal tried with passing in a property for the token doesnt look like it works as there's no property or column interactable with that property

    Trying to update a bearer type credential with the update usernamepassword credentials doesnt work as it's the wrong type

    given the other options I dont think you can update a bearer token with swis

    @chantal if you can gather a bearer token, in an earlier step in an apipoller chain you can use it later in the sequence if you're lucky and it's formatted nicely

    Otherwise you're looking at like SQL/SAM/Something custom

  • I have figured out my issue! I wasn't connecting to the database properly

  • Interesting, wouldnt have guessed that. What did you end up doing with the bearer in the end?