0

I'm trying to run a script that would get a list of users in bitwarden and output it to a file called bitmembers.

Below is the script where XXXX is my API bearer token

#!/bin/bash

CURL="/usr/bin/curl"
BITHTTP="https://api.bitwarden.com/public/members"
CURLARGS="-X GET"

header='-H "accept: text/plain" -H "Authorization: Bearer XXXX"'

$CURL $CURLARGS $BITHTTP $header > /tmp/bitmembers

Below is the error I'm getting when script is ran:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: text
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: Bearer
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: XXXX

Below is the curl command and confirmed works:

curl -X GET "https://api.bitwarden.com/public/members" -H  "accept: text/plain" -H  "Authorization: Bearer XXXX"

It looks like it's breaking down in the header portion. Can you point out what I'm missing?

Nina G
  • 269
  • 5
  • 17
  • BITHTTP='"https://api.bitwarden.com/public/members"' Can you try adding single quotes to the url including the double quotes? – Pamela Sarkisyan Dec 01 '21 at 23:20
  • I tried adding single quotes as you suggested and in addition to the errors above, now it says ```curl: (3) URL using bad/illegal format or missing URL``` – Nina G Dec 02 '21 at 14:03
  • seems like the curl options like header and get need to be in separate variables – Pamela Sarkisyan Dec 02 '21 at 16:43

1 Answers1

0

I believe the issue is in the curl options not being set in separate variables, so the below should resolve the errors:

#!/bin/bash

CURL="/usr/bin/curl"
CURLARGS="-X GET"
BITHTTP="https://api.bitwarden.com/public/members"
header="-H"
accept="accept:text/plain"
auth="Authorization:Bearer XXXX"

$CURL $CURLARGS $BITHTTP $header "$accept" $header "$auth" > /tmp/bitmembers

This answer seems like a good approach to send variables as options to the main curl command. Example:

CURL_OPTIONS=( -X GET "$BITHTTP" -H "$accept" -H "$auth" )
$CURL "${CURL_OPTIONS[@]}"