Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
Created January 17, 2024 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikStyp/41559951c437c9d611da6ad67457079c to your computer and use it in GitHub Desktop.
Save DominikStyp/41559951c437c9d611da6ad67457079c to your computer and use it in GitHub Desktop.
CURL request in bash: send access_token request, and second request to import users from file
#!/bin/bash
RESPONSE=$(curl --location --insecure --request POST 'http://server.local/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=123' \
--data-urlencode 'client_secret=456' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=123' \
--data-urlencode 'scopes=full_access email openid')
if [ -z "$RESPONSE" ]; then
echo "ERROR: empty response"
exit 1
fi
ACCESS_TOKEN=$(echo $RESPONSE| jq -r .access_token);
if [ -z "$ACCESS_TOKEN" ]; then
echo "ERROR: empty access token"
exit 1
fi
# this will upload the file which should exist in ./payload/usersToImport.csv
curl --verbose --location --insecure --request POST "http://server.local/resources/v1/users/import" \
--header "authorization: Bearer $ACCESS_TOKEN" \
--form 'file=@./payload/usersToImport.csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment