Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Getting Started >

Error oauth_problem = signature_invalid & oauth_problem_advice = Failed to validate signature

Started by Yorgan Cuenca -   in Getting Started

I'm having problem with POST request, but only when I start from data I got with a previous GET.

If I do a post with new data, I have no problem at all.

This is what I do:

- send a GET request go retrieve a contact

- update the contact LastName

- send the modified data back

and then I get the error that is the title of this post.

I'm using the PHP API wrapper library, updated to the last release.

I tried posting via the API preview the XML that I'm sending via the wrapper library, and everything is ok.

So can somebody tell me what is wrong?

I can show the code, if needed.

Thanks.
I am having the same issue using Node.js

https://community.xero.com/developer/discussion/2900620/
 

Nikolai Mouraviev  

I'm not sure where you are going wrong here, even if there were illegal XML characters in your POST data, it should not throw a signature invalid error.

Are you able to modify one of the tests (there is a test for POST Contact) with the data you are attempting to update, and see if you get the same result?

If so, post the sample XML here and I can check it out.
If you don't get an error when using the sample tests, then the issue must lie with your implementation of the sample PHP code.

@Nikolai - I doubt your issue is the same
 

Ronan Quirke (Community Manager)  

Hi Ronan,
and thank you for your advice.
I tried to run the sample code, and got the same error.

Here's the code:

(omitted because i receive this error "There was an error formatting your answer.")

The xml is exactly the one from the sample code.
Another weird thing: even the GET sample doesn't work, something I never had problems with in my code.

I'd also like to stress that if I POST a new contact, I have no problem. The only problem is only if I tried to update an existing one.

I also tried the other php class, and I have no problem with that (but I know the class is not supported anymore).
So if you see anything wrong with the code above, let me know. If you need more info, let me know.
And thank you in advance.
 

Yorgan Cuenca  

let me know if I can send you the code, I can't put it in this form.
 

Yorgan Cuenca  

Use the git button in the reply window to share a GitHub gist link.
 

Ronan Quirke (Community Manager)  

This code is provided by the developer community - Xero does not warrant it in any way
 

Yorgan Cuenca  

I forgot to add, application type is private
 

Yorgan Cuenca  

Ok, sorry I didn't pick up on this earlier, but the test data in POST Contact is UTF-8 encoded data with odd things like German language characters. When it is retrieved back out, it is not in UTF-8 encoded form so attempting to POST it directly back again, results in a signature error.

You just picked some bad sample data to start with I believe.

The sample code doesn't handle things like character encoding, but you could use the utf8_encode function to do so.
 

Ronan Quirke (Community Manager)  

I tried to make it simpler by getting rid of the utf8 chars.

This code is provided by the developer community - Xero does not warrant it in any way


I still get the same error.
 

Yorgan Cuenca  

Well running that code myself returns no errors.
You might try posting the var_dump output as a last ditch attempt to see where things might be going wrong.

If you do a find and replace on the consumer key value, it should be safe to post here.
 

Ronan Quirke (Community Manager)  

This code is provided by the developer community - Xero does not warrant it in any way


I substituted the consumer_key and secret with <string>

Thank you for your patience and support.
 

Yorgan Cuenca  

Sorry, I meant run your script with the correct settings for consumer_key etc, but once you have captured the output, then remove the sensitive details. The output above isn't much use as you have removed the consumer key before making the API call, which generates a different error.
 

Ronan Quirke (Community Manager)  

Sorry if I misled you. I substituted the strings in the output of var_dump. The call was made with the right parameters.
 

Yorgan Cuenca  

May I ask you a big favour?
Could you provide an example code that queries Xero to get a contact by ContactID, change the FirstName, and saves it back to Xero?

All the example I see just make one call to Xero. I seem to have problem with a second call (that's where we started from). Like I said, I don't have any problem with David Pitman's wrapper library. There could be smething between the 2 calls that I'm not doing, but I can't see what it could be.

Thanks
 

Yorgan Cuenca  

I did some more testing.
If I do 2 get calls, everything is fine. If I do one POST call, everything is fine. If I do a GET and a POST; the POST is denied with the above error.

My time is running out and I have to decide which wrapper library to use. David Pitman's wrapper seems to work ok, but I know it is not supported anymore and has been tested only for private application, which is ok right now, but might not be in the future.
I'd rather not reinvent the wheel and use a maintained library, but I can't figure out what I'm doing wrong.

Please help if you can.

Thank you.
 

Yorgan Cuenca  

Your original post said it was a signature error, but the var_dump you posted had a different error "string(85) "oauth_problem=token_rejected&oauth_problem_advice=Token%20has%20not%20been%20provided""

I would advise you to re-check your code. We can't write the code for you, but if the only way you can get it to work is using the other code sample, do that - there isn't an issue with the XeroOAuth-PHP library that I can tell.
 

Ronan Quirke (Community Manager)  

you're absolutely right, I did not realize that. Sorry for that mistake.
Anyway with the code here attached the error is what is stated in the subject of this thread:

This code is provided by the developer community - Xero does not warrant it in any way
 

Yorgan Cuenca  

Sorry to bump an old thread, but I have the same issue using the Xero PHP library.
I can't execute 2 POSTs in a row. They both go well if run independently, but if I run them one after another the second one gets:
"oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature"

Were there any updates concerning this thread?

Edit:
I found out that if I have 2 POSTs in a row, the second POST has $XeroOAuth->request_params blank (even if I am passing some xml). I'm not sure why. However, if I execute unset($XeroOAuth->request_params)) before running the POST, then it will contain the xml and I have no issues
 

Roberto Montebelli  

Thanks Roberto - this fixed the issue for me and saved me a lot of heartache!
 

Brian Kelly  

I came across this thread after I got the error message today, and all I had to do was delete my application on Xero, re-register one with new keys and certificates, upload those to my project, and everything worked fine after that.
 

Carl Reyneke  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal  

I am also having the same issue with public/private key pair. Could you please help me out to get resolve this issue. Currently I am using trial version and generated the key pairs as mentioned at:

https://developer.xero.com/documentation/api-guides/create-publicprivate-key
 

Himmat Paliwal