Open GoogleCodeExporter opened 9 years ago
Gah, I'm not doing anything right today. Please disregard this ticket, the
issue is that I was screwing around with the code that generates the signature
Original comment by hippysoy...@gmail.com
on 11 Aug 2010 at 6:20
Hi,
we are experiencing problems with the put request in connection with the XERO
API.
The authentication seems ok, however OAuth puts the actual PUT params into the
request header and NOT in the req body.
The post request works.
In order to update Payments for approved invoices in Xero only the PUT method
can be used.
Original comment by ukuhnha...@gmail.com
on 9 Sep 2010 at 12:51
Hi,
The issue here is that Xero don't support the full OAuth v1.0a spec - as I
understand it it's completely valid to put the params into the request header,
but Xero don't support it.
The difficulty with putting the params in the body is that depending on if you
use v1.0 or v1.0a the parameters are included or not included in the signature
- ie it's not possible to support both versions simultaneously.
I'd be very happy to be corrected if someone knows otherwise!
Original comment by hippysoy...@gmail.com
on 9 Sep 2010 at 1:00
Original comment by morten.f...@gmail.com
on 29 Mar 2011 at 6:00
I am trying to create a New Invoice through Xero's API but somehow i am getting
the response as
"oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20s
ignature". I am playing with it from couple of days but i didn't manage to
create the Invoice on Xero. Below is my function that i am using to create a
new Invoice. It is written in Groovy.
def createInvoiceByPost(def invoice,String key,String secret,String verifier) {
try {
def config = conf.config
String consumerName = config.consumerName
String apiUrl = config.invoiceUrl
String xml = invoiceService.convertToXml(invoice)
xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?> "+xml
xml = URLEncoder.encode(xml,"UTF-8")
String body = "<form enctype=\"application/x-www-form-urlencoded;charset=UTF-8\" method=\"post\">"+
" <input type=\"hidden\" id=\"xml\" name=\"xml\" value=\"${xml}\"/>"+
"</form>"
//body = URLEncoder.encode(body,"UTF-8")
def resp = oauthService.accessResource(apiUrl,consumerName,["key":key,"secret":secret],
"post",["oauth_verifier":verifier,"${OAuth.OAUTH_SIGNATURE_METHOD}":OAuth.HMAC_SHA1,"${OAuthClient.PARAMETER_STYLE}":ParameterStyle.AUTHORIZATION_HEADER],
[],body,null,
"application/x-www-form-urlencoded; charset=utf-8")
return resp
}
catch(Exception exp) {
println exp.toString()
}
}
Can anybody tell me where i am making any mistake. I have to create a new
Invoice. Off-course it will be created as Draft. I have tested the XML that my
"convertToXml" function generated. I pasted that XML on API viewer and executed
that and that worked fine. The Invoice was generated but i am not able to
generate it through my code.
Any help will be highly appreciated.
Original comment by sikander...@gmail.com
on 1 Feb 2012 at 11:54
Hi,
you could be encountering the same error that I had - I ended up checking out
the OAuth source and modifying it to put the params in the request header as
per my comment 3 http://code.google.com/p/oauth/issues/detail?id=180#c3. I
forget if Xero use version 1.0 or 1.0a (you might need to contact Xero), but
you'll need to look up the spec to see what changes you need to make with the
generation of the signature.
I can't really submit my changes as they will break compatibility with one of
the versions.
hope that helps!
Original comment by hippysoy...@gmail.com
on 2 Feb 2012 at 6:25
In case this helps anyone, I got around this by setting the body myself like
this:
parameters = new ArrayList<>(1);
parameters.add(new OAuth.Parameter("xml", payments.toXml()));
byte[] form = OAuth.formEncode(parameters).getBytes(UTF_8);
String url = xeroConfig.getApiBaseUrl() + PAYMENTS_ENDPOINT;
OAuthMessage request = accessor.newRequestMessage(PUT, url, null, new ByteArrayInputStream(form));
request.getHeaders().add(new OAuth.Parameter(HttpHeaders.CONTENT_ENCODING, UTF_8));
request.getHeaders().add(new OAuth.Parameter(HttpHeaders.CONTENT_TYPE, OAuth.FORM_ENCODED));
request.getHeaders().add(new OAuth.Parameter(HttpHeaders.CONTENT_LENGTH, String.valueOf(form.length)));
//
OAuthMessage m = oauthClient.invoke(request, ParameterStyle.BODY);
Hope that helps someone else having trouble with the xero API
Cheers
dalyc
Original comment by Mr.Colin...@gmail.com
on 3 Dec 2014 at 12:55
The issue comes from the new HttpMessage not adding the body for put messages.
In HttpMessage on like 132 it needs to also check for the PUT message type.
final boolean isPost = OAuthMessage.POST.equalsIgnoreCase(from.method) || OAuthMessage.PUT.equalsIgnoreCase(from.method);
Original comment by plugboy@gmail.com
on 28 Jan 2015 at 8:49
Original issue reported on code.google.com by
hippysoy...@gmail.com
on 11 Aug 2010 at 6:05