I feed some env variables in circle CI project and using its API(https://circleci.com/docs/api/#list-environment-variables) trying to get values of env vars but it returns hidden values except the last 4 digits(xxxx4134). I want to list and fetch the values to be utilized in my code, so how can I unhide it or have a way to get the proper values in response to be used in other parts of code?

Below is the code I tried in javascript that does return env vars values but hidden.

const options= {
        url: 'https://circleci.com/api/v1.1/project/github/projectName/envvar?circle-token={{apiToken}}',
        method: 'GET',
        json: true,
        resolveWithFullResponse: true,
    }
    request(options).then(response => { console.log('response=', response.body)
for (var count = 0; count < response.body.length; count++) {
            var item = response.body[count]
            if (item.name == 'C_ID') {
                const cId = item.value
            }
        })

Actual API call Response :

  "name" : "A_TOKEN",
  "value" : "xxxx7177"
}, {
  "name" : "C_ID",
  "value" : "xxxx51fa"
}]```

Upon using parsed json values, for instance of C_ID i.e; "xxxx51fa" in my other API calls results in error as it doesn't understand xxxx.

Any suggestions or help greatly appreciated.

1 Answers

0
Daniel A. White On

It appears requesting a single environment variable will return the whole value.

curl https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/envvar/:name?circle-token=:token

where :name is the environment variable you desire.