# Empty JSON Messages

**URL:** <http://forum.companieshouse.gov.uk/t/empty-json-messages/333>\
**Category:** API Issues\
**Created:** [November 3, 2015, 5:27pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333 "2015-11-03T17:27:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](http://forum.companieshouse.gov.uk/u/richard)\
**Post date:** [November 3, 2015, 5:27pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/1 "2015-11-03T17:27:16Z")

</div>

I am presently getting empty JSON messages “ **{}** ” on the web service, for instance on the URLs [https://api.companieshouse.gov.uk/search/officers?q=XXXXX&items\_per\_page=20&start\_index=1](https://api.companieshouse.gov.uk/search/officers?q=XXXXX&items_per_page=20&start_index=1) and [https://api.companieshouse.gov.uk/search/companies?q=YYYYY&items\_per\_page=20&start\_index=1](https://api.companieshouse.gov.uk/search/companies?q=YYYYY&items_per_page=20&start_index=1) Having authenticated on the HTTP Header. This is happening with my Java code and on JMeter.

Is there a problem with the service or is there a mistake that I am making?

---

<div class="post-metadata">

**Author:** ![amaddaford](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/amaddaford/32/45_2.png) [@amaddaford](http://forum.companieshouse.gov.uk/u/amaddaford)\
**Post date:** [November 9, 2015, 12:40pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/2 "2015-11-09T12:40:45Z")

</div>

Hi Richard,

Both of those requests work for me. Are you still having this problem?

Andrew

---

<div class="post-metadata">

**Author:** ![richard](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](http://forum.companieshouse.gov.uk/u/richard)\
**Post date:** [November 13, 2015, 9:53am UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/3 "2015-11-13T09:53:04Z")

</div>

Yes, I am. Although it varies based on how I am calling it.

On Java I am getting a 502 (Bad Gateway) error, using the URL [https://api.companieshouse.gov.uk/search/companies?q=king&items\_per\_page=20&start\_index=1](https://api.companieshouse.gov.uk/search/companies?q=king&items_per_page=20&start_index=1) (I have searched for “king” on the Try It function on the website and it returns values) authorised using the pair **“Authorization”, “Basic “+encodedPassword[from the API Key field on the website after login]+”:”**, with values: **“Content-Type”, “text/json”** , **“Content-Length”, “10000000”** and the request method GET.

On JMeter I am getting just the empty brackets mentioned before for the JSON response, server name **[api.companieshouse.gov.uk](http://api.companieshouse.gov.uk)** using https GET, with **Authorization, “Basic “+encodedPassword[from the API Key field on the website after login]+”:”** and **Content-Type, text/json** , using the path search/companies?q=king&items\_per\_page=20&start\_index=1

I can’t see anything that varies from the instructions given on the forum or in the documentation, so I am not too sure what the problem would be. I presume there are no problems using this service internationally?

Thanks

---

<div class="post-metadata">

**Author:** ![ajmaddaford](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@ajmaddaford](http://forum.companieshouse.gov.uk/u/ajmaddaford)\
**Post date:** [November 13, 2015, 4:10pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/4 "2015-11-13T16:10:31Z")

</div>

The 502 error implies it’s a server error on our side but I’ve tried the same query a number of times and it worked every time.

Can you try (replacing ENCODED\_API\_KEY with your encoded API key):  
`curl -v https://api.companieshouse.gov.uk/search/companies\?q\=king\&items_per_page\=20\&start_index\=1 --header "Authorization: Basic <ENCODED_API_KEY>"`

---

<div class="post-metadata">

**Author:** ![amaddaford](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/amaddaford/32/45_2.png) [@amaddaford](http://forum.companieshouse.gov.uk/u/amaddaford)\
**Post date:** [November 13, 2015, 4:26pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/5 "2015-11-13T16:26:28Z")

</div>

The 502 error implies it’s a server error on our side but I’ve tried the same query a number of times and it worked every time.

Can you try (replacing ENCODED\_API\_KEY with your encoded API key):  
`curl -v https://api.companieshouse.gov.uk/search/companies\?q\=king\&items_per_page\=20\&start_index\=1 --header "Authorization: Basic <ENCODED_API_KEY>"`

---

<div class="post-metadata">

**Author:** ![richard](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](http://forum.companieshouse.gov.uk/u/richard)\
**Post date:** [November 13, 2015, 4:34pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/6 "2015-11-13T16:34:17Z")

</div>

I was able to get results using the command “curl -uXXXXXX: [https://api.companieshouse.gov.uk/search/companies?q=king&items\_per\_page=20&start\_index=1](https://api.companieshouse.gov.uk/search/companies?q=king&items_per_page=20&start_index=1)” (XXXXXX being the API\_Key on the website after login)

I still haven’t been able to get this to work on either JMeter or Java code.

But I am a bit confused as to what I am supposed to submit on the Authorization property, is it the API\_Key as on the site with a colon appended (as on my curl command) or a base 64 encoding of the key with colon on the end?

The command that you sent results in a “HTTP/1.1 401 Unauthorized” error, both with XXXXXX: and base64Encode(XXXXXX:)

---

<div class="post-metadata">

**Author:** ![richard](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](http://forum.companieshouse.gov.uk/u/richard)\
**Post date:** [November 13, 2015, 4:57pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/7 "2015-11-13T16:57:35Z")

</div>

I added an **Accept** header and now I can access the service 😀

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![amaddaford](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/amaddaford/32/45_2.png) [@amaddaford](http://forum.companieshouse.gov.uk/u/amaddaford)\
**Post date:** [November 13, 2015, 6:00pm UTC](http://forum.companieshouse.gov.uk/t/empty-json-messages/333/8 "2015-11-13T18:00:52Z")

</div>

No problem. Please report back if you have any further problems.
