Code Monkey home page Code Monkey logo

Comments (10)

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

What credentials are you using? It should be the username you use to login and the API key you generated for your user, not your password.

The command help states:

Credential object containing token id as the username and token secret as the password

As per the API documents:

Authentication to use the API is primarily done using API Tokens. Once the "Access System API" permission has been assigned to a user, a "API Tokens" section should be visible when editing their user profile. Choose "Create Token" and enter an appropriate name and expiry date, relevant for your API usage then press "Save". A "Token ID" and "Token Secret" will be immediately displayed. These values should be used...

from psbookstack.

ShowMeIT avatar ShowMeIT commented on August 20, 2024

Thank you for your reply,

When I run: Connect-BookStackAPI -Url 'xxxx.xxxxxxx.xxx' -Credential yyyyyyyyy

With yyyyyyyyy as my bookstack username (I've also tried the email address associated with the account with the same result) I get a powershell credential pop-up window asking for a password - when I enter my bookstack password I get the following message:

Invoke-WebRequest : {"error":{"code":401,"message":"No authorization token found on the request"}}
At line:74 char:25

  • ... $iWebReq = (Invoke-WebRequest @invokeWebRequest -SessionVariable glob ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
      eption
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

from psbookstack.

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

Sorry, it's not your username, it's your token ID as I quoted originally:

Credential object containing token id as the username and token secret as the password

On the Edit Profile page of BookStack, when you created a new token you were shown two values - your ID and Secret. In order to connect with the -Credential parameter you need to use the Token ID and Token Secret values.

image

Connect-BookStackAPI -Url 'xxx' -Credential (Get-Credential)

When prompted enter your Token ID as the username and Token Secret as the password.
You could also pass in your ID as part of the connection command:

Connect-BookStackAPI -Url 'xxx' -Credential (Get-Credential {TokenID})

and then enter the Token Secret as the password

from psbookstack.

ShowMeIT avatar ShowMeIT commented on August 20, 2024

Hi,

Thank you again for your help with this.
I am still doing something wrong; I have my Token ID and Secret - when I try with the command below, I get the following output:

Connect-BookStackAPI -Url xxxxxx.xxxx.xxx -Credential (Get-Credential {xxxxxxxxxxxxxxxxxxxxxxxxxxxxx})
Get-Credential : Cannot process argument transformation on parameter 'Credential'. userName
At line:1 char:76

  • ... om.au -Credential (Get-Credential {xxxxxxxxxxxxxxxxxxxxxxxxxx})
  •                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Get-Credential], ParameterBindingArgumentTransformationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.PowerShell.Commands.GetCredentialCommand

And I get the following when using the Connect-BookStackAPI -Url 'xxx' -Credential (Get-Credential) command:

Connect-BookStackAPI -Url 'xxxxx.xx.xxx' -Credential
At line:1 char:62

  • ... onnect-BookStackAPI -Url 'xxxxx.xx.xxx' -Credential <PSCreden ...
  •                                                             ~
    

The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported

Maybe I have an issue with my PowerShell?

from psbookstack.

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

Try this:

$cred = Get-Credential
Connect-BookStackAPI -Url 'xxx' -Credential $cred

using your token id as the username and token secret as the password

What version of PowerShell are you using?

from psbookstack.

ShowMeIT avatar ShowMeIT commented on August 20, 2024

Hi,
PowerShell Version:
5.1.22000.2003

When run the commands you suggested, I get the following output from the second command:

Invoke-WebRequest : {"error":{"code":401,"message":"No authorization token found on the request"}}
At line:74 char:25

  • ... $iWebReq = (Invoke-WebRequest @invokeWebRequest -SessionVariable glob ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
      eption
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
      Connection Status:
      PS C:\WINDOWS\system32>

from psbookstack.

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

OK, try the following command (not sure if windows has curl)

curl -k --request GET --url https://{url}/api/books --header 'Authorization: token <token_id>:<token_secret>'

Putting in your token id and secret as required.
Can you also double check that the user account associated with the token has role access to the API

from psbookstack.

ShowMeIT avatar ShowMeIT commented on August 20, 2024

Hi,
Thank you for your response.
User has 'Access System API' ticked in their role assignment.

Output from command below:
PS C:\WINDOWS\system32> curl -k --request GET --url https://xxxxxxx/api/books --header 'Authorization: token xxx:xxx'
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'k'.
At line:1 char:6

  • curl -k --request GET --url https://xxxxxxx/api/books -- ...
  •  ~~
    
    • CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

from psbookstack.

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

You need to use actual curl, not the PowerShell alias of it.

from psbookstack.

My-Random-Thoughts avatar My-Random-Thoughts commented on August 20, 2024

Close as no response for 3 weeks

from psbookstack.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.