Skip to content

Commit

Permalink
Remove deprecated environment variable API docs (#2979)
Browse files Browse the repository at this point in the history
* Remove "Encrypting base64 encoded values" section

* Replace deprecated variable endpoint documentations with reference to API docs page

* Update content/rest-api/applications.md

Co-authored-by: helinanever <[email protected]>

* Update content/rest-api/applications.md

Co-authored-by: helinanever <[email protected]>

---------

Co-authored-by: helinanever <[email protected]>
  • Loading branch information
priitlatt and helinanever authored Feb 12, 2025
1 parent 13c2be4 commit 995b10c
Showing 1 changed file with 1 addition and 224 deletions.
225 changes: 1 addition & 224 deletions content/rest-api/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,231 +172,8 @@ base64 id_rsa | pbcopy
{{< /highlight >}}



## Encrypting base64 encoded values

#### Example

{{< highlight bash "style=paraiso-dark">}}
curl -H "Content-Type: application/json" \
-H "x-auth-token: $CM_API_TOKEN" \
-d '{
"appId": "YOUR_APP_ID",
"value": "BASE64_ENCODED_VALUE"
}' \
-X POST https://api.codemagic.io/apps/YOUR_APP_ID/encrypt-environment-variable
{{< /highlight >}}


#### Response

{{< highlight json "style=paraiso-dark">}}
{
"encrypted": "Encrypted(Z0FBQUFBQmZMVkhwb3Q3QlJtRlVOeVFJcEJvTTRtWnZablpqMS0xN2V6dllTell1ODZSd2FUcnNqMUlZT09QY1paV0pjbVRfUlVJeDUxRWIzX1paOEZlc1dSdi1XMXlkUFVIdjNIZ2VqcE5Ja0tpMjlPWjhlSTQ9)"
}
{{< /highlight >}}


## Modify application variables and secrets

Codemagic allows you to fetch and modify application variables and secrets using the REST API. Note that the API works slightly differently depending on whether your application is configured to use the `Workflow Editor` or `YAML configuration`.

For yaml, variables and secrets are manually configured on the **Environment variables** tab in your application settings. These variables and secrets can be accessed in your configuration file across all workflows with the use of [groups](../building/environment-variable-groups). Variables configured for the `Workflow Editor` are specific to one workflow.

### Fetch variables

`GET /apps/:id/variables`

Based on the application id provided, returns the configured variables.

#### Example

{{< highlight bash "style=paraiso-dark">}}
curl -XGET \
-H 'x-auth-token: <API Token>' \
-H "Content-type: application/json" \
'https://api.codemagic.io/apps/<app_id>/variables'
{{< /highlight >}}


#### Response

##### Response for applications using codemagic.yaml
{{< highlight json "style=paraiso-dark">}}
[
{
"group": "production",
"id": "619e329e0ca5fe19c3780c74",
"key": "FOO",
"secure": true,
"value": "[HIDDEN]"
}
]
{{< /highlight >}}


##### Response for applications using Workflow Editor
{{< highlight json "style=paraiso-dark">}}
[
{
"id": "61b06dbe72d7ad0017679014",
"key": "FOO",
"secure": true,
"value": "[HIDDEN]",
"workflowId": "60f0520c4c8734015080d401",
"workflowName": "Default Workflow"
}
]
{{< /highlight >}}


### Add new variable

`POST /apps/:id/variables/`

#### Parameters

| **Name** | **Type** | **Description** |
| --------------- | -------- | --------------- |
| `key` | `string` | **Required.** Name of the variable. |
| `value` | `string` | **Required.** Value of the variable. For binary data use base64 to encode the contents. |
| `group` | `string` | **Optional.** Required for applications using yaml configuration. Name of the `group` that the variable should be added to. If the group does not exist, it will be created. |
| `workflowId` | `string` | **Optional.** Required for applications using Workflow Editor. ID of the `workflow` that the variable should be added to. |
| `secure` | `boolean` | **Optional.** By default, the variable is encrypted. Set to `false` to not encrypt the newly added variable. |

#### Example

{{< highlight bash "style=paraiso-dark">}}
curl -XPOST \
-H 'x-auth-token: <API TOKEN>' \
-H "Content-type: application/json" \
-d '{
"key": "FOO",
"value": "foobar",
"group": "production",
"secure": true
}' \
'https://api.codemagic.io/apps/<app_id>/variables'
{{< /highlight >}}


#### Example of adding file variables

It is possible to pass text-based files to the `cURL` command with the help of CLI tools, such as `sed` or `awk` (which is used in the example below).
These tools provide options to properly retain newlines, which are essential for some files (e.g. private keys) to function correctly.


{{< highlight bash "style=paraiso-dark">}}
FILE=$(awk 1 ORS='\\n' file_path)
curl -XPOST -H 'x-auth-token: <API TOKEN>' \
-H 'Content-Type: application/json;charset=utf-8' \
-d "{
\"key\":\"FOO\",
\"value\":\"$FILE\",
\"group\":\"production\",
\"secure\": true
}" \
'https://api.codemagic.io/apps/<app_id>/variables'
{{< /highlight >}}


To add binary-based files (e.g. images), they need to be [`base64 encoded`](../variables/environment-variable-groups/#storing-sensitive-valuesfiles) first before passing them to the value parameter as strings. Note that the values will have to be `base64 decoded` during the build in order to be used.


#### Response

##### Response for applications using codemagic.yaml
{{< highlight json "style=paraiso-dark">}}
{
"group": "production",
"id": "619e329e0ca5fe19c3780c74",
"key": "FOO",
"secure": true,
"value": "[HIDDEN]"
}
{{< /highlight >}}


##### Response for applications using Workflow Editor
{{< highlight json "style=paraiso-dark">}}
{
"id": "61b06dbe72d7ad0017679014",
"key": "FOO",
"secure": true,
"value": "[HIDDEN]",
"workflowId": "60f0520c4c8734015080d401",
"workflowName": "Default Workflow"
}
{{< /highlight >}}


### Update existing variable

`POST /apps/:id/variables/:variable_id`

#### Parameters

| **Name** | **Type** | **Description** |
| --------------- | -------- | --------------- |
| `value` | `string` | **Required.** New value for the updated variable. |
| `secure` | `boolean` | **Optional.** By default, the variable is encrypted. Set to `false` to not encrypt the newly added variable. |


#### Example
For up-to-date information on managing environment variables and secrets for apps configured using codemagic.yaml, please refer to the **Secrets and Environment Vars** endpoints in [Codemagic REST API documentation](https://codemagic.io/api/v3/schema).

{{< highlight bash "style=paraiso-dark">}}
curl -XPOST \
-H 'x-auth-token: <API Token>' \
-H "Content-type: application/json" \
-d '{
"value": "foobar2",
"secure": false
}' \
'https://api.codemagic.io/apps/<app_id>/variables/<variable_id>'
{{< /highlight >}}


#### Response

##### Response for applications using codemagic.yaml
{{< highlight json "style=paraiso-dark">}}
{
"group": "production",
"id": "619e329e0ca5fe19c3780c74",
"key": "FOO",
"secure": false,
"value": "foobar2"
}
{{< /highlight >}}


##### Response for applications using Workflow Editor
{{< highlight json "style=paraiso-dark">}}
{
"id": "61b06dbe72d7ad0017679014",
"key": "FOO",
"secure": false,
"value": "foobar2",
"workflowId": "60f0520c4c8734015080d401",
"workflowName": "Default Workflow"
}
{{< /highlight >}}


### Remove variable

`DELETE /apps/:id/variables/:variable_id`

#### Example

{{< highlight bash "style=paraiso-dark">}}
curl -XDELETE \
-H 'X-Auth-Token: <API Token>' \
-H "Content-type: application/json" \
'https://api.codemagic.io/apps/<app_id>/variables/<variable_id>'
{{< /highlight >}}


#### Response

The response status code of a successful deletion is `204`.

0 comments on commit 995b10c

Please sign in to comment.