/envvar endpoint not working for API

The /envvar endpoint is showing unusual behavior. I’m unable to create environment variables using the endpoint programmatically (i.e. via ?circle-token=... from my own script), but the web app appears to use it just fine. As best I can tell, it seems like it doesn’t work when authenticating using the query param, but it works fine is authenticating using cookies.

When authenticating using query params, I get:

{  "message" : "You must choose a name for this environment variable"}

Even if I send an identical request body to the one sent by the web app’s own XHR request.

Can you share the code that you are using to make this? This endpoint is a part of the wrapper I wrote and it does not appear to have any issues. API — circleci.py 2.0.0 documentation

Code example: https://github.com/levlaz/circleci.py/blob/master/circleci/api.py#L598

Note that this endpoint requires a name and a value for your env var, so it looks like either you are not providing a name, or it is unable to read the name key.

I am also struggling with this.
I can successfully “GET” the envvars but passing any variant of the “body” to the “POST” request fails, e.g.

  • {“A”: 1} with “raw” JSON encoding

API endpoint 1.1 still since for v2 net even “GET” is working.

@levlaz Looked at your code but that did not help me. I am using R and have “POST” requests working for other endpoints but /envvar won’t work.

Found the issue.

Instead of passing a simple key:value pair as JSON, circle wants to have two key:value pairs for ONE env var. The names for both need to be explictily set as “name” and “value”, as specified also in the Circle CI API help pages.

{"name":"foo","value":"xxxx"}

1 Like

Thanks for posting your solution, I am glad to hear that you were able to get this sorted out.

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