Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Problems with invoice PDF format download

Started by Luis Soto -   in API Endpoints

Hello.
I have a problem when I try to download invoice in PDF format. I send Accept="application/pdf" in the Head, but the Xero API return a XML data.
I use a java language and that is my code:
try {
OAuthClient client = new OAuthClient(new HttpClient3());
OAuthAccessor accessor = buildAccessor();
OAuthMessage message = client.invoke(accessor, OAuthMessage.GET, endpointUrl + "Invoices/" + invoiceid, parameters);
message.getHeaders().add(new OAuth.Parameter("Accept", "application/pdf"));
invoicePdfBytes = message.getBodyAsStream();

} catch (Exception ex) {
ex.printStackTrace();
}

Thanks.
Im also having the same issue where xml is being returned when accept='application/pdf' is being sent in the headers.

Here my code..

var session = _xeroSessionFactory.CreatePartnerSession();
var accessToken = session.RenewAccessToken();

var request = session.Request();
request.Context.RequestMethod = "GET";
request.Context.RawUri = uri;
request.SignWithToken(accessToken);
request.WithAcceptHeader("application/pdf");

var response = request.ToConsumerResponse();

return response;

Any suggestions would be helpful.

Cheers,
Byron
 

Support CashFlowBuilder  

@Luis The Accept header should be a http one not an OAuth one as you have it in your code
@Byron not sure why yours isn't working, but seems to be working for others

Maybe try requesting JSON: http://blog.xero.com/developer/api-overview/http-get/ and see if that works?

I'm doubtful it will - I am guessing you are just getting the default response (XML) and your Java library is not sending any accept header.
 

Ronan Quirke (Community Manager)  

Hi Luis,

I think you will need to re-write the HttpClient3 and add the headers to it's internal HttpClient rather than the OAuthClient.

I don't really like the way the OAuth library makes it hard to get to the HttpClient -I will try writing a better HttpClient3 when I get some time.

Does that all make sense?
 

Ross Jourdain  

Hi Luis,

As Ross said, OAuthClient does not support arbitrary HTTP headers.

You can work around this by using OAuthAccessor directly, see the working example.

Also have a look at the README for how to get the tests to pass.

Ben
 

Ben Biddington (Xero Staff)  

I'd like to download PDF of invoices.
Does anybody have any working code to do this?
Thanks
Philip
 

Philip Meldrum