Use Gam Redirect to send to a spreadsheet the output of another gam command

483 views
Skip to first unread message

Leonardo Barbosa

unread,
Aug 14, 2023, 11:30:30 AM8/14/23
to GAM for Google Workspace
Hi all!

I'm trying to use "gam redirect" to send the output of a GAM command to a Google Spreadsheet that I have here.

To give you some context, I'm creating Contact Groups using the following GAM command below:

gam user myu...@mydomain.com create contactgroup name "Company Contact Label"

When I use this command, I receive the following output in my Command Prompt/Bash screen:

User: myu...@mydomain.com, Contact Group: contactGroups/1234567a8bcd9e10, Created


I want to have this output in a row of my Google Spreadsheet. How can I do this? Please keep in mind that in this example I'm using only one user (myu...@mydomain.com), but I have over 1000 users that I need to retrieve these contact group IDs and have in a spreadsheet for me.

Maybe something like the following command below should work? I'm just not sure what is going wrong with it:

gam redirect csv - multiprocess todrive tdfileid [My_Spreadsheet_ID_here] tdsheet id:[My_Spreadsheet_Sheet_GID_here] tdupdatesheet csv "myPrimaryEmailAddressHere.csv" gam user ~primaryEmail create contactgroup name "Company Contact Label"


Thank you for your help! (In case there is no solution/the API doesn't support, I can try using stderr and stdout to output everything in CSVs on my local machine).

Best,
Leonardo

Ross Scroggs

unread,
Aug 14, 2023, 11:42:49 AM8/14/23
to google-ap...@googlegroups.com
Leonardo,

This won't work as the output from create contactgroup is written to stdout, not a csv file

gam redirect csv - multiprocess todrive tdfileid [My_Spreadsheet_ID_here] tdsheet id:[My_Spreadsheet_Sheet_GID_here] tdupdatesheet csv "myPrimaryEmailAddressHere.csv" gam user ~primaryEmail create contactgroup name "Company Contact Label"

Test this; write the output to a local file, then update your Google Sheet
gam redirect stdout ./ContactGroups.txt multiprocess csv "myPrimaryEmailAddressHere.csv" gam user ~primaryEmail create contactgroup name "Company Contact Label"

gam user sheet...@domain.com update drivefile [My_Spreadsheet_ID_here] gsheet id:[My_Spreadsheet_Sheet_GID_here] localfile ContactGroups.txt

Ross

--
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/107489dd-19fa-4c7d-b39b-2e3d74e9bfcan%40googlegroups.com.


--

Ross Scroggs

unread,
Aug 14, 2023, 7:27:33 PM8/14/23
to google-ap...@googlegroups.com
Leonardo,

With 6.62.07 you can now do what you want in a single command; add the option csv at the end of the command.
gam redirect csv - multiprocess todrive tdfileid [My_Spreadsheet_ID_here] tdsheet id:[My_Spreadsheet_Sheet_GID_here] tdupdatesheet csv "myPrimaryEmailAddressHere.csv" gam user ~primaryEmail create contactgroup name "Company Contact Label" csv


Ross

--

Ross Scroggs

unread,
Aug 15, 2023, 12:26:58 AM8/15/23
to google-ap...@googlegroups.com
Leonardo,

With 6.62.08 you can now get more informative output by using the addcsvdata option to output additional columns os d ata.
gam redirect csv - multiprocess todrive tdfileid [My_Spreadsheet_ID_here] tdsheet id:[My_Spreadsheet_Sheet_GID_here] tdupdatesheet csv "myPrimaryEmailAddressHere.csv" gam user ~primaryEmail create contactgroup name "Company Contact Label" csv addcsvdata name "Company Contact Label"


Ross
----
Ross Scroggs


Leonardo Barbosa

unread,
Aug 15, 2023, 10:07:28 AM8/15/23
to GAM for Google Workspace
Thank you so much, Ross! It worked!

Also, I'm so grateful that you updated GAM just to add this feature that I requested. For real though, I didn't even add it as an Issue in your Github repo. You're a great person, and I hope you keep having an amazing life!
Reply all
Reply to author
Forward
0 new messages