jerseyclickatell

Getting Error for jersey client request headers?


I need to set these headers for a REST call via jersey client. clickatell message send rest call

curl -i \
            -X POST \
            -H "X-Version: 1" \
            -H "Content-Type: application/json" \
            -H "Authorization: Bearer Your Authorization Token" \
            -H "Accept: application/json" \

My code is:

Client client = Client.create();
WebResource webResource = client.resource("https://api.clickatell.com/rest/message");

ClientResponse response = webResource
                            .header("Authorization", "Bearer clickATellAuthKey")    
                            .header("X-Version", "1")
                            .header("Content-Type", "application/json")
                            .header("Accept", "application/json")
                            .post(ClientResponse.class, input); 

I am getting this error:

{"error":{"code":"001","description":"Authentication failed","documentation":"http://www.clickatell.com/help/apidocs/error/001.htm"}}

the document says the auth header is not specified. The request is working fine in Postman ( chrome restful client extension) with same headers

Need help.


Solution

  • Thanks @whatever_sa there are some improvements required as well in code and also there was an issue with auth key your answer at least make me check the auth key once more. here is the working code

        ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)                   
                            .header(MessageServices.API_AUTH_HEADER, MessageServices.AUTH_KEY)
                            .header(MessageServices.API_VERSION_HEADER, MessageServices.API_VERSION)                            
                            .post(ClientResponse.class, input);