CVS Bash - ERROR 404 : resource Not Found: userKey ...

167 views
Skip to first unread message

Shawn Haigh

unread,
Mar 15, 2023, 6:06:38 PM3/15/23
to GAM for Google Workspace
Greeting everyone,

Would anyone know why the below BASH script and CSV file would return the following error? I'm using a Mac v12.6.1. and GAM v6.50 - Python 3.11.2

$ ./batch.sh users.csv
ERROR: 404: Resource Not Found: userKey - userNotFound

CSV File:
$ cat users.csv
User One,u....@domain.com
User Two,u....@domain.com 

BASH script:
$ cat batch.sh
#!/bin/bash
OLDIFS=$IFS

gam_command()
{
    OAUTHFILE=~/bin/gam/oauth2.txt /bin/gam/gam info user "$email"
}

IFS=,
while read name email; do
    gam_command $email  
done < $1

IFS=$OLDIFS

I also know of the native GAM Bulk Operations command gam csv <csv-filename> gam <regular command>"  but I want to use a bash script in my case.

Perhaps I'm missing something simple,  but after some extensive searching the GAM Wiki, Google, and Google Groups I can't seem to find an answer.

... any ideas?

Thanks
Shawn


This message and all attachments are confidential. Any unauthorized review, use, disclosure, or distribution is prohibited. If you believe this message has been sent to you by mistake, please notify the sender by replying to this email, and delete the message and its attachments without disclosing them.

Ross Scroggs

unread,
Mar 15, 2023, 6:12:56 PM3/15/23
to google-ap...@googlegroups.com
Shawn,

Try this:

Ross
$ cat batch.sh
#!/bin/bash
OLDIFS=$IFS
OAUTHFILE=~/bin/gam/oauth2.txt 

gam_command()
{
    ~/bin/gam/gam info user "$1"

}

IFS=,
while read name email; do
    gam_command $email  
done < $1

IFS=$OLDIFS
--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/3ad22784-7cb8-4dd4-a2de-5137f7a8c616n%40googlegroups.com.


--

Jay Lee

unread,
Mar 15, 2023, 6:18:22 PM3/15/23
to google-ap...@googlegroups.com
I'd also just try having the function echo the GAM command you want to run. I don't believe Bash will parse CSV rows divided by , by default.

Fwiw, I wrote GAM's batch command capabilities after using a Bash script much like yours half a dozen times and becoming uhhh... "Agitated" 😁

I love Bash but also it's awful and I sometimes really hate it. At least it's not PowerShell though (ducks behind a wall).

Jay

Kevin Melillo ✉

unread,
Mar 16, 2023, 8:28:23 AM3/16/23
to google-ap...@googlegroups.com
I don't see where you are actually referencing the users.csv file...  you aren't reading it into the code...  although sometimes I miss things..  am I crazy here?

#!/bin/bash
INPUT=~/gam-data/users.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }

while read name email
do
  gam_command $email
  emailSuffix="@ieee.org"
done < $INPUT
IFS=$OLDIFS


gam_command()
{
    OAUTHFILE=~/bin/gam/oauth2.txt /bin/gam/gam info user "$email"
}
--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/3ad22784-7cb8-4dd4-a2de-5137f7a8c616n%40googlegroups.com.


--
photo
Kevin Melillo
Electronic Communications Analyst, Information Technology

Phone: 732.465.6609 | Mobile: 732-609-4331

Email: k.me...@ieee.org

445 Hoes Lane Piscataway, NJ 08854

Kevin Melillo ✉

unread,
Mar 16, 2023, 8:33:28 AM3/16/23
to google-ap...@googlegroups.com
Your code:
while read name email; do
    gam_command $email  
done < $1

$1 does not exist for it to read from...  so view my code above, and it will read from the specified file.

Shawn Haigh

unread,
Mar 16, 2023, 9:25:57 AM3/16/23
to google-ap...@googlegroups.com
Thanks for the replies so far...

Quick update still no success  :-(

I'm passing the csv file as the 1st argument to the script ($1), and I know the csv is being parsed correctly when I change the gam_command function to the following:

$ cat batch.sh
#!/bin/bash
OLDIFS=$IFS
OAUTHFILE=~/bin/gam/oauth2.txt

gam_command() {
    #~/bin/gam/gam info user "$1"
    echo "Email: $1"
}

IFS=,
while read name email; do
  gam_command $email
  exit 0
done < $1

IFS=$OLDIFS

$ ./batch.sh users.csv
Email: u....@domain.com

The emails are passed to the function and I get the expected output. Why I get an error when uncommenting the gam command ~/bin/gam/gam info user "$1" is still a mystery.

Shawn


You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/nMg4h0vO35E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAKM%3DbobR7q7xFJUaYX7NyjDtHU3tTthgPeqCnTzJV1ZAi1CC5A%40mail.gmail.com.

Shawn Haigh

unread,
Mar 16, 2023, 10:20:56 AM3/16/23
to google-ap...@googlegroups.com
I even did away with the function and tried the simplest approach. Still does not work so I suspect there is something else at play here which I hope the community can shed some light on:

$ while read email; do /Users/user/bin/gam/gam info user "$email"; done < users.txt
ERROR: 404: Resource Not Found: userKey - userNotFound

$ cat users.txt

Thanks!

Maj Marshall Giguere

unread,
Mar 16, 2023, 10:29:27 AM3/16/23
to google-ap...@googlegroups.com
Shawn;

As a suggestion try typing the raw command on the command line with one of the values from the csv file. Are you using advanced gam or classic gam, do the users in your csv file actually exist?

Maj Marshall E Giguere

NH Wing Director of IT

Civil Air Patrol, U.S. Air Force Auxiliary

GoCivilAirPatrol.com

nhwg.cap.gov

Volunteers serving America's communities, saving lives, and shaping futures.



TheBitwiseBadger

unread,
Mar 17, 2023, 4:27:08 AM3/17/23
to GAM for Google Workspace
Marking this as SOLVED.

It turns out it was a bytecode order mark at the beginning of in the CSV file which messed up the call to the API.

TIP: Use a plain txt editor like nano to build your CSV,  Don't use MS Excel! :-0

Kudos to Ross, for his troubleshooting help.

Shawn
Reply all
Reply to author
Forward
0 new messages