Passing a variable with the Groups API

Hello. I am new to Okta and am trying to get familiar with the API. I was working on a script that could create multiple Groups in our new Okta tenant but with the way the curl command is formatted my array variable is not being read. I’ve used other APIs but not one that seems to require this kind of formatting. The variable is just read as plain text and a Group is made with the name of the variable. Here is my script for reference. Thanks in advance!

#!/bin/bash


array=("IT" "Engineering" "Finance")

for i in "${array[@]}"
do	
	curl POST \
	-H "Accept: application/json" \
	-H "Content-Type: application/json" \
	-H "Authorization: SSWS $api_key" \
	-d '{
		"profile": {
			"name": "$i"
		}
	}' "https://$oktadomain/api/v1/groups"
done```

Hi @carndt87!

Can you try the following instead:

#!/bin/bash

array=("IT" "Engineering" "Finance")

for i in "${array[@]}"
do
  curl -v -X POST
  -H "Accept: application/json" \
	-H "Content-Type: application/json" \
	-H "Authorization: SSWS $api_key" \
	-d '{
		"profile": {
			"name": "'$i'"
		}
	}' "https://$oktadomain/api/v1/groups"
done

I made sure to preserve the iterator, i, per bash formatting as mentioned here shell - Difference between single and double quotes in Bash - Stack Overflow

That did it. Thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.