Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Signature invalid error when getting/uploading attachments with special characters in filename

Started by SelviAsp Xero -   in API Endpoints

Tried to upload an attachment via API with special characters like ;, %, # and so on and received signature_invalid error. Looks like the filename itself is part of the URL and not a param. It is used to construct the OAuth signature and hence the signature is not valid. Few special characters like $, @ worked fine.

I used https://api.xero.com/api.xro/2.0 and 2.1 as well. I tried by encoding the special character to UTF-8 like %3Bimage.jpeg instead of ;image.jpeg in the URL but it didn't help.

I tried passing the UTF-8 encoding for the failing characters to the request but still, the request failed. Few characters when encoded were processed successfully but not all characters. Can anyone please help with this?
I recommend writing a function and passing the image name in. Inside the function you can regex and replace any offending characters with underscores. Then return the new string from the function and use that. A quick search on stackoverflow will probably return a portentously solution for your language.

Sidney Maestre (Community Manager)  

Thanks for looking into this.

I agree that replacing the failing characters with underscores will work but I am looking for a solution where the filename is not changed. If the API does not support characters without replacing, then I have to see the impact of changing the filename.

Please let me know if there is any other way to resolve this without changing the filename.

SelviAsp Xero  

Hi Sidney,

Do we have any updates on this?

SelviAsp Xero  

Hi SelviAsp,

I don't have anything else to add beyond my first comment. I wrote the Java SDK and found the same issue with special chars in file names when posting to the API. The best solution I found was to remove the special characters. The API returns an ID for the attachment and I would recommend storing that value for future retrieval.Performing a GET using the filename with special chars. can cause problems as well. I recommend using the AttachmentId and not the filename when retrieving the file.

Sidney Maestre (Community Manager)  

Thanks much. Hope team Xero fixes this in the near future.

SelviAsp Xero