Skip to content

Instantly share code, notes, and snippets.

@adborden
Created July 15, 2019 22:43
Show Gist options
  • Save adborden/0ea2fd243910b711e41a9f36a740fa81 to your computer and use it in GitHub Desktop.
Save adborden/0ea2fd243910b711e41a9f36a740fa81 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Adds the user to the list of organizations as the specified role.
#
# Usage ./org_membership.sh <email> <role> < subagencies.txt
set -o errexit
set -o pipefail
set -o nounset
function organization_member_create () {
local username=$1
local organization=$2
local role=$3
payload=$(mktemp)
cat <<EOF > "$payload"
{"id":"$organization","username":"$username","role":"$role"}
EOF
#--data "id=$organization" \
#--data "username=$username" \
#--data "role=$role" \
curl -vvvv --fail -H "Authorization: $CKAN_API_KEY" -H "Cookie: auth_tkt=1" \
--data-binary "@$payload" \
-H "Content-Type: application/json;charset=utf-8" \
'https://inventory.data.gov/api/3/action/organization_member_create'
rm "$payload"
}
username=$1
role=${2:-member}
while read organization; do
organization_member_create "$username" "$organization" "$role"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment