How to setup app with REST API And Set Environment Variables #1069
-
I have managed to setup REST API to setup app and upload environment variables from bash script but the problem is that if the app is already setup manually from website then only environment variables are added but if i setup the app using API then getting error as invalid id and also there is no way to setup app type like Android Flutter then config type I have to manually do that on website |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @burhankhanzada Let me know if I understood correctly and if the above solution works for you. |
Beta Was this translation helpful? Give feedback.
-
Well the issue is from my side because when app is added it sends response back with app id and name then i want to use that app id and run another script to add environment variables but the command i was using to extract app_id from response is added double quotes so there for its giving me INVALID_APP_ID I solved it with this scripts but there is no way to setup app type and config type through API
#!/usr/bin/env bash
repo_url=$(cat <../secrets/repo_url.txt)
echo repo_url="$repo_url"
github_ssh_private_key=$(base64 <../secrets/github_ssh_private_key.asc)
github_ssh_key_passphrase=$(cat <../secrets/github_ssh_key_passphrase.txt)
echo github_ssh_private_key="$github_ssh_private_key"
echo github_ssh_key_passphrase="$github_ssh_key_passphrase"
json=$(
jq -n \
--arg repo "$repo_url" \
--arg ssh_key "$github_ssh_private_key" \
--arg ssh_passphrase "$github_ssh_key_passphrase" \
'{
"repositoryUrl": $repo,
"sshKey": {
"data": $ssh_key,
"passphrase": $ssh_passphrase
}
}'
)
echo json="$json"
codemagic_token=$(cat ../secrets/codemagic_token.txt)
echo codemagic_token="$codemagic_token"
echo Add application from "$repo_url"
response=$(curl -X POST "https://api.codemagic.io/apps" \
-H "x-auth-token: $codemagic_token" \
-H "Content-Type: application/json" \
-d "$json")
app_id=$(echo "$response" | jq -r '._id')
echo $app_id >../secrets/codemagic_app_id.txt
./upload_enviroment_varaibles.sh
#!/usr/bin/env bash
githun_token=$(cat ../secrets/github_token.txt)
echo github_token="$githun_token"
gpg_private_key=$(base64 <../secrets/burhan_private_key.gpg)
echo gpg_private_key="$gpg_private_key"
json=$(
jq -n \
--arg githun_token "$githun_token" \
--arg gpg_private_key "$gpg_private_key" \
'[
{
key: "GITHUB_TOKEN",
value: $githun_token,
group: "all",
secure: true
},
{
key: "GPG_PRIVATE_KEY",
value: $gpg_private_key,
group: "all",
secure: true
}
]'
)
echo json="$json"
env_count=$(echo "$json" | jq '. | length')
codemagic_token=$(cat ../secrets/codemagic_token.txt)
echo codemagic_token="$codemagic_token"
codemagic_app_id=$(cat ../secrets/codemagic_app_id.txt)
echo codemagic_app_id="$codemagic_app_id"
echo Adding enviroment varaibles
for ((i = 0; i < env_count; i++)); do
data=$(echo "$json" | jq -r .["$i"])
curl -X POST "https://api.codemagic.io/apps/$codemagic_app_id/variables" \
-H "x-auth-token: $codemagic_token" \
-H "Content-Type: application/json" \
-d "$data"
done
|
Beta Was this translation helpful? Give feedback.
Well the issue is from my side because when app is added it sends response back with app id and name then i want to use that app id and run another script to add environment variables but the command i was using to extract app_id from response is added double quotes so there for its giving me INVALID_APP_ID I solved it with this scripts but there is no way to setup app type and config type through API