Execute API's for multiple entities

Harness API’s here https://harness.io/docs/api/

These API can be used to perform action for single entity.

We can use a simple shell script to execute the API’s for multiple entities.

Sample API curl command to Delete Invite https://harness.io/docs/api/tag/Invite#operation/deleteInvite

Curl command :

curl -i -X DELETE \
  'https://app.harness.io/gateway/ng/api/invites/{inviteId}?accountIdentifier=string' \
  -H 'x-api-key: YOUR_API_KEY_HERE'

Here we need to enter inviteId,
In case we need to execute this for multiple inviteIds.

We can create a Text File Ex: ids.txt
Enter multiple inviteids in that.

Also these ids we can get from another API : https://harness.io/docs/api/tag/Invite#operation/getPendingUsersAggregated

curl -i -X POST \
  'https://app.harness.io/gateway/ng/api/invites/aggregate?accountIdentifier=xxxxxxxxxxxx&pageSize=50&sortOrders=%5Bobject%20Object%5D' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: xxxxxxxx' \
  -d '{}'

We can use a simple shell script :

for value in $(cat ids.txt); do
  echo $value
  curl -i -X DELETE https://app.harness.io/gateway/ng/api/invites/$value?accountIdentifier=**accountid** -H 'x-api-key: **APIKEY**'
done

You can create an API key Add and Manage API Keys - Harness.io Docs to be used in the curl command.

2 Likes