Trying to get basic company information - API giving {"error":"Empty Authorization header","type":"ch:service"}

I am trying to pass in the URL https://api.companieshouse.gov.uk/company/{company_number}. According to the documentation https://developer.companieshouse.gov.uk/api/docs/company/company_number/readCompanyProfile.html#here it does not require specific header parameters or any authentication.

Instead I keep getting {“error”:“Empty Authorization header”,“type”:“ch:service”} whenever i pass in the URL and put a company number.

Any help would be appreciated, Thanks.

a quick search on the forum should help:-
https://forum.aws.chdev.org/search?q=Empty%20Authorization%20header

I have searched through and none of them provide a solution to my problem

Please post what your are sending in your headers.
Please post at least a code snippet detailing how you are calling our API.
As the error suggests, the problem is with the value you’re sending.

    ` //url of api service
        String data =  "https://api.companieshouse.gov.uk/search/companies?q=Apple";
        try {
            HttpsURLConnection conn = null;
            URL url = new URL(data);
            conn = (HttpsURLConnection) url.openConnection();
            conn.setRequestProperty(HttpHeaders.AUTHORIZATION, mContext.getString(R.string.api_key_companies_house));
            conn.setReadTimeout(10000 /* milliseconds */ );
            conn.setConnectTimeout(15000 /* milliseconds */ );
            conn.setDoOutput(true);
            conn.setRequestMethod("GET");
            //Log.i("responseCode1", String.valueOf(conn.getResponseCode()));
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            Log.i("responseCode2", String.valueOf(conn.getResponseCode()));
            wr.flush();
            wr.close();
            String line;
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));

            // Read Server Response
            while((line = reader.readLine()) != null) {
                sb.append(line);
                break;
            }
            reader.close();
            return sb.toString();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }catch(MalformedURLException e){
            e.printStackTrace();
        }catch (ProtocolException e){
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }

        return data;
    }`

I get a 404 response code. This is written in Java for an Android device. The authorisation is working now, but I am not receiving any data back from the server.

Have you managed to get your system working with our API ?

Unfortunately no. This time I’m getting a “400 Bad Request” from the server. Is there any example of working code in Java, C# or Python that I can have a look at?

reading the following may help:-