Created
January 17, 2024 15:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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