Jump to content

Jason Fuller

Members
  • Posts

    1
  • Joined

  • Last visited

Jason Fuller's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. I apologize for dragging out an old post, but this is the first hit when you Google "passwordstate api curl." If you're using the API key for auth: #!/bin/bash api_key='abc123' # PasswordState API key pass_id='123456' # PasswordState PasswordID url="https://example.com/api/passwords/$pass_id" json=$(curl -sS --request GET --header "APIKey: $api_key" "$url") To address the OPs question, note that in the documentation, it shows PowerShell passing an array (with "key = value" pairs) as an argument for the headers: -Header @{ "APIKey" = "<apikey>" } ...where curl expects them in the HTTP header format: --header "APIKey: $key" If you have jq installed, you can filter for the first password returned: echo "$json" | jq -r '.[0].Password' Or you don't want to install jq (or can't), you can use regex to pull out the value: # If you have GNU grep (Linux): echo "$json" | grep -oP '(?<="Password":").*?(?=")' # If not, this _should_ be POSIX compliant (BSD, MacOS, etc), but I haven't tested thoroughly: echo "$json" | sed -n 's/.*"Password":"\([^"]*\)".*/\1/p' ...just know that parsing structured data with regex is an exercise in frustration and very imperfect, though it usually works for very specific, very limited things.
×
×
  • Create New...