# Api.get(/environments/NAME) is not returning JSON

**URL:** <https://discourse.chef.io/t/api-get-environments-name-is-not-returning-json/4874>\
**Category:** Chef Infra (archive)\
**Created:** [January 10, 2014, 10:55pm UTC](https://discourse.chef.io/t/api-get-environments-name-is-not-returning-json/4874 "2014-01-10T22:55:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ostap36](https://avatars.discourse-cdn.com/v4/letter/o/f6c823/32.png) [@ostap36](https://discourse.chef.io/u/ostap36)\
**Post date:** [January 10, 2014, 10:55pm UTC](https://discourse.chef.io/t/api-get-environments-name-is-not-returning-json/4874/1 "2014-01-10T22:55:50Z")

</div>

Ohai Chefs,

I am trying to programmatically pull existing environment json for a given environment name off chef server via an authenticated API GET request to /environments/NAME endpoint

knife exec getEnvjson.rb

getEnvjson.rb:

require “awesome\_print”

env = api.get("/environments/STAGE")

ap env

exit 0

What I am getting back is just STAGE text value instead of the expected fully blown json definition of the STAGE environment.

Am I missing something?

Running 11.4.0 chef server, thinking whether this is a known issue that’s been addressed in the subsequent releases and I should upgrade?

Thank you in advance.

Alex

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [January 10, 2014, 10:59pm UTC](https://discourse.chef.io/t/api-get-environments-name-is-not-returning-json/4874/2 "2014-01-10T22:59:45Z")

</div>

What you get back is JSON with some magic hints such that Ruby turns it into a Chef::Environment object by default, which defines to\_s to just return its name. You can either use it as a Ruby object, or use another client library that doesn't automatically inflate objects.

--Noah

On Jan 10, 2014, at 2:55 PM, Alex Myasnikov [amyasnikov@practicefusion.com](mailto:amyasnikov@practicefusion.com) wrote:

> Ohai Chefs,
> 
> I am trying to programmatically pull existing environment json for a given environment name off chef server via an authenticated API GET request to /environments/NAME endpoint
> 
> knife exec getEnvjson.rb
> 
> getEnvjson.rb:
> 
> require "awesome\_print"
> 
> env = api.get("/environments/STAGE")
> 
> ap env
> 
> exit 0
> 
> What I am getting back is just STAGE text value instead of the expected fully blown json definition of the STAGE environment.
> 
> Am I missing something?
> 
> Running 11.4.0 chef server, thinking whether this is a known issue that’s been addressed in the subsequent releases and I should upgrade?
> 
> Thank you in advance.
> 
> Alex

---

<div class="post-metadata">

**Author:** ![ostap36](https://avatars.discourse-cdn.com/v4/letter/o/f6c823/32.png) [@ostap36](https://discourse.chef.io/u/ostap36)\
**Post date:** [January 11, 2014, 1:07am UTC](https://discourse.chef.io/t/api-get-environments-name-is-not-returning-json/4874/3 "2014-01-11T01:07:48Z")

</div>

Got it, thank you Noah

-----Original Message-----  
From: Noah Kantrowitz [[mailto:noah@coderanger.net](mailto:noah@coderanger.net)]  
Sent: Friday, January 10, 2014 3:00 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: api.get(/environments/NAME) is not returning JSON

What you get back is JSON with some magic hints such that Ruby turns it into a Chef::Environment object by default, which defines to\_s to just return its name. You can either use it as a Ruby object, or use another client library that doesn't automatically inflate objects.

--Noah

On Jan 10, 2014, at 2:55 PM, Alex Myasnikov [amyasnikov@practicefusion.com](mailto:amyasnikov@practicefusion.com) wrote:

> Ohai Chefs,
> 
> I am trying to programmatically pull existing environment json for a given environment name off chef server via an authenticated API GET request to /environments/NAME endpoint
> 
> knife exec getEnvjson.rb
> 
> getEnvjson.rb:
> 
> require "awesome\_print"
> 
> env = api.get("/environments/STAGE")
> 
> ap env
> 
> exit 0
> 
> What I am getting back is just STAGE text value instead of the expected fully blown json definition of the STAGE environment.
> 
> Am I missing something?
> 
> Running 11.4.0 chef server, thinking whether this is a known issue that's been addressed in the subsequent releases and I should upgrade?
> 
> Thank you in advance.
> 
> Alex
