# Chef API

**URL:** <https://discourse.chef.io/t/chef-api/5289>\
**Category:** Chef Infra (archive)\
**Created:** [May 12, 2014, 7:40am UTC](https://discourse.chef.io/t/chef-api/5289 "2014-05-12T07:40:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dvir\_Levy](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dvir\_Levy](https://discourse.chef.io/u/Dvir_Levy)\
**Post date:** [May 12, 2014, 7:40am UTC](https://discourse.chef.io/t/chef-api/5289/1 "2014-05-12T07:40:03Z")

</div>

Hello,  
Im not sure if this is the right address.

I am trying to create a PHP library to work with Chef API.  
I am using hosed Chef and this is the library :

> **[dv1r/php-chef](https://github.com/dv1r/php-chef)**
>
> Opscode Chef API PHP library. Contribute to dv1r/php-chef development by creating an account on GitHub.

  
I have also opened a ticket in support :  
[https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534)  
and there is an open Stack-Overflow question :  

> <https://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json>

All of the information to my problem is there, but to sum up  
Every PUT/POST request that contains data being passed to the API  
comes back as "Invalid JSON".  
I've looked at the request from every direction I could think of and it  
should work.  
Is there any way someone here can help me?  
Does chef expect a kind of JSON that I've never heard of?

Thank you,  
Dvir Levy

P.S  
If this is the wrong place, could you point me to the right place? 🙂

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [May 12, 2014, 9:51am UTC](https://discourse.chef.io/t/chef-api/5289/2 "2014-05-12T09:51:04Z")

</div>

Le 2014-05-12 09:40, Dvir Levy a écrit :

> Hello,  
> Im not sure if this is the right address.
> 
> I am trying to create a PHP library to work with Chef API.  
> I am using hosed Chef and this is the library : [GitHub - dv1r/php-chef: Opscode Chef API PHP library](https://github.com/dv1r/php-chef) [1]  
> I have also opened a ticket in support : [https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534) [2]  
> and there is an open Stack-Overflow question : [php - Opscode Chef REST API invalid JSON - Stack Overflow](http://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json) [3]
> 
> All of the information to my problem is there, but to sum up  
> Every PUT/POST request that contains data being passed to the API  
> comes back as "Invalid JSON".  
> I've looked at the request from every direction I could think of and it should work.  
> Is there any way someone here can help me?  
> Does chef expect a kind of JSON that I've never heard of?
> 
> Thank you,  
> Dvir Levy
> 
> P.S  
> If this is the wrong place, could you point me to the right place? 🙂

Answered on SO.

Mainly the problem is json to object, new property and object to json.

I had to cast to an array to ensure adding items works properly with the  
library.

Hope it helps.

Tensibai

## Links:

[1] [GitHub - dv1r/php-chef: Opscode Chef API PHP library](https://github.com/dv1r/php-chef)  
[2] [https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534)  
[3]  
[php - Opscode Chef REST API invalid JSON - Stack Overflow](http://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json)

---

<div class="post-metadata">

**Author:** ![Dvir\_Levy](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dvir\_Levy](https://discourse.chef.io/u/Dvir_Levy)\
**Post date:** [May 12, 2014, 11:48am UTC](https://discourse.chef.io/t/chef-api/5289/3 "2014-05-12T11:48:41Z")

</div>

Hello Tensibai,

First of all thank you for the help.

Did casting the response work for you?  
For me, it doesn't change the outcome of the "json\_encode()".  
I have checked that I am really getting an array after casting, but the  
output of the json\_encode is an object.  
I still get "Invalid JSON" :\

Again, Thank You,  
-- Dvir Levy

On Mon, May 12, 2014 at 12:51 PM, Tensibai [tensibai@iabis.net](mailto:tensibai@iabis.net) wrote:

> Le 2014-05-12 09:40, Dvir Levy a écrit :
> 
> Hello,  
> Im not sure if this is the right address.
> 
> I am trying to create a PHP library to work with Chef API.  
> I am using hosed Chef and this is the library :  
> [GitHub - dv1r/php-chef: Opscode Chef API PHP library](https://github.com/dv1r/php-chef)  
> I have also opened a ticket in support :  
> [https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534)  
> and there is an open Stack-Overflow question :  
> [php - Opscode Chef REST API invalid JSON - Stack Overflow](http://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json)
> 
> All of the information to my problem is there, but to sum up  
> Every PUT/POST request that contains data being passed to the API  
> comes back as "Invalid JSON".  
> I've looked at the request from every direction I could think of and it  
> should work.  
> Is there any way someone here can help me?  
> Does chef expect a kind of JSON that I've never heard of?
> 
> Thank you,  
> Dvir Levy
> 
> P.S  
> If this is the wrong place, could you point me to the right place? 🙂
> 
> Answered on SO.
> 
> Mainly the problem is json to object, new property and object to json.
> 
> I had to cast to an array to ensure adding items works properly with the  
> library.
> 
> Hope it helps.
> 
> Tensibai

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [May 12, 2014, 2:37pm UTC](https://discourse.chef.io/t/chef-api/5289/4 "2014-05-12T14:37:51Z")

</div>

I have added an exemple of my code on Stack Overflow.

It works for me (OOS 11.0.10), but maybe hosted chef is more  
conservative, you may try to dump the data within the library to ensure  
what is sent...

Tensibai

Le 2014-05-12 13:48, Dvir Levy a écrit :

> Hello Tensibai,
> 
> First of all thank you for the help.
> 
> Did casting the response work for you?  
> For me, it doesn't change the outcome of the "json\_encode()".  
> I have checked that I am really getting an array after casting, but the output of the json\_encode is an object.  
> I still get "Invalid JSON" :
> 
> Again, Thank You,  
> -- Dvir Levy
> 
> On Mon, May 12, 2014 at 12:51 PM, Tensibai [tensibai@iabis.net](mailto:tensibai@iabis.net) wrote:
> 
> Le 2014-05-12 09:40, Dvir Levy a écrit :
> 
> Hello,  
> Im not sure if this is the right address.
> 
> I am trying to create a PHP library to work with Chef API.  
> I am using hosed Chef and this is the library : [GitHub - dv1r/php-chef: Opscode Chef API PHP library](https://github.com/dv1r/php-chef) [1]  
> I have also opened a ticket in support : [https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534) [2]  
> and there is an open Stack-Overflow question : [php - Opscode Chef REST API invalid JSON - Stack Overflow](http://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json) [3]
> 
> All of the information to my problem is there, but to sum up  
> Every PUT/POST request that contains data being passed to the API  
> comes back as "Invalid JSON".  
> I've looked at the request from every direction I could think of and it should work.  
> Is there any way someone here can help me?  
> Does chef expect a kind of JSON that I've never heard of?
> 
> Thank you,  
> Dvir Levy
> 
> P.S  
> If this is the wrong place, could you point me to the right place? 🙂
> 
> Answered on SO.
> 
> Mainly the problem is json to object, new property and object to json.
> 
> I had to cast to an array to ensure adding items works properly with the library.
> 
> Hope it helps.
> 
> Tensibai

## Links:

[1] [GitHub - dv1r/php-chef: Opscode Chef API PHP library](https://github.com/dv1r/php-chef)  
[2] [https://www.getchef.com/support/tickets/17534](https://www.getchef.com/support/tickets/17534)  
[3]  
[php - Opscode Chef REST API invalid JSON - Stack Overflow](http://stackoverflow.com/questions/23456790/opscode-chef-rest-api-invalid-json)
