-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"createInvoiceAttachmentByFileName" Create attachment but not correct content file #679
Comments
PETOSS-402 |
Thanks for raising an issue, a ticket has been created to track your request |
We should get paid for all the time wasted in understanding and using your crapy API and following your uselessly lengthy approval processes... what a shame. |
Why closing it? The issue is still there |
It seems like you are complaining about this problem of mine. And I replaced it with another solution without using xero-node. So I thought I should close it to avoid bothering everyone. |
I'm complaining about Xero. The issue is still unresolved, and it affects production too. I would share your solution here for other people to avoid wasting time trying to upload attachments. |
This needs to be re-opened. I'm having the same issue when trying to upload files via If it makes a difference, I'm trying to attach
|
I'm so sorry, my mistake. I will reopen it now |
+1 |
@nguyenphudung93dn @mryraghi can you share the solution that fixed the problem, I am also facing the same issue as reported above. |
@nguyenphudung93dn @mryraghi Kindly share the solution that you used to resolve the attachment issue. |
Hi guys, I ended up using the API... |
@mryraghi But previously you said that you got the solution. |
@nguyenphudung93dn Can u please share the solution to fix the create attachment problem. |
@mryraghi, @utkarsh3020 This is my solution that is working for me
|
@nguyenphudung93dn Hi, I am Sending image url and invoiceId from frontend and remaining processing performing like this const invoiceID = payload.invoiceID; const fileName = "xero-inv.jpeg"; const refresh_token = req.refresh_token; await xero.setTokenSet(tokenSet); try {
} catch (err) { Can u please tell me how to resolve this issue |
@utkarsh3020 You can't use the SDK method for file attachments - it doesn't work - that's the whole point of this issue. Instead you'll need to make a request to the API endpoint directly with Axios or fetch or similar. Since you've used Axios in the code you provided, I've shown an Axios example. Basically the same as what you had, I just added const createAttachment = async (req, res) => {
const { payload } = req.body
const invoiceID = payload.invoiceID
const img = payload.img // Presuming this is the image url
const fileName = "xero-inv.jpeg"
// Determine the content type of the image
const contentType = mime.lookup(fileName)
const includeOnline = true
const idempotencyKey = uuidv4()
const refresh_token = req.refresh_token
const tokenSet = refresh_token || JSON.parse(req.headers["authorization"])
const xeroTenantId = req.headers["xero-tenant-id"]
await xero.setTokenSet(tokenSet)
try {
// Download the image from the provided URL
const response = await axios.get(
img,
{
headers: { Accept: contentType }, // Should work without this, but...
responseType: "arraybuffer"
}) You don't need any of this: // Create a temporary file to save the downloaded image
const tempFilePath = path.join(__dirname, "../public/images/xero-inv.png")
fs.writeFileSync(tempFilePath, response.data)
// Create a readable stream from the temporary file
const body = fs.createReadStream(tempFilePath)
body.on("data", (chunk) => {
console.log("Data received:", chunk.length, "bytes")
})
// Listen for the 'end' event, which indicates that the entire file has been read
body.on("end", () => {
console.log("File reading completed")
})
// Listen for the 'error' event, which indicates any errors that occur during reading
body.on("error", (err) => {
console.error("Error reading file:", err)
}) Example of the Axios request: // Upload the attachment to Xero
const uploadResponse = await axios.post(
`https://api.xero.com/api.xro/2.0/Invoices/${invoiceID}/Attachments/${fileName}?IncludeOnline=${includeOnline}&IdempotencyKey=${idempotencyKey}`,
response.data,
{
headers: {
Authorization: `Bearer ${tokenSet.access_token}`,
"Xero-tenant-id": xeroTenantId,
"Content-Type": contentType,
"Accept": "application/json",
},
responseType: "json",
}
) Change console.log("Res success", uploadResponse.data)
res.send(uploadResponse.data)
} catch (err) {
console.log("Error occurred during attachment upload:", err)
res.status(500).send({ error: "Attachment upload failed" })
}
} |
@tsdevau Thanks, now it is working absolutely fine. |
The fault seems to be in accountingApi.js, around line 2202:
Changing the middle line to be:
Appears to fix it in my case. I suspect in the general case you would need to coalesce all the elements of that array. Of course this isn't something that us end users can do as the auto-generated package file is likely get overwritten breaking functionality. Maybe this is helpful to the developers to get it fixed? |
Scratch that, still an issue with v7.0.0 |
Still an issue with v8.0.0 |
Hey @nguyenphudung93dn, @bobsquito , @tsdevau , @rworkduo, @paulcorke Apologies for the inconvenience caused by this bug. This attachment bug has been addressed in xero-node v9.0.0. Please try with the new version and let us know with your feedback. |
********* Testing ************* Build from OAS 5.0.0 ## What's Changed * Bugfix #679 | createInvoiceAttachmentByFileName Create attachment but not correct content file * Bugfix #686 | Attempt to parse object as JSON results in JSON parse body failed written to console ## Breaking Change * Removed PageInfo metadata object and added pagination metadata object for select Api.Accounting endpoints * Added ultimate sub plans for Api.Accounting
SDK xero-node Version 5.1.0
Describe the bug
I tested API with this code:
But result: File uploaded but not content
The text was updated successfully, but these errors were encountered: