Skip to content

Instantly share code, notes, and snippets.

@Sdy603
Created October 30, 2024 15:47
Show Gist options
  • Save Sdy603/2b8c6af0398d70e84365d516fe7a526c to your computer and use it in GitHub Desktop.
Save Sdy603/2b8c6af0398d70e84365d516fe7a526c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Initial URL for the groups endpoint with pagination (max 100 items per page)
base_url='https://git.ws.cgm.com/api/v4/groups?per_page=100'
# Authentication token and proxy setup
token='cgmglpat-fL<TOKEN REMOVED>HHz'
proxy="http://$DX_PROXY_USER:[email protected]:80"
# Initialize variables
page=1
next_page=true
while [ "$next_page" == true ]; do
# Construct the URL with the current page
url="$base_url&page=$page"
echo "Fetching: $url"
# Execute the curl request
response=$(curl --location --insecure \
--header "PRIVATE-TOKEN: $token" \
-x $proxy \
-s -D - $url)
# Extract the body and headers from the response
body=$(echo "$response" | sed -n '/^\r$/,$p')
headers=$(echo "$response" | sed -n '1,/^\r$/p')
# Display or process the response body (here, just echoing it)
echo "$body"
# Check if there is a next page
next_page_value=$(echo "$headers" | grep -i 'x-next-page:' | awk '{print $2}' | tr -d '\r')
if [ -n "$next_page_value" ]; then
page=$next_page_value
else
next_page=false
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment