Discussions
Help with Moving Attachments & Notes Between Jobs via API
1 day ago by mark
Hi Support Team,
I’m trying to move attachments and notes from an existing job to a new job using the ServiceM8 API. Below is my current approach:
// Fetch attachments
const attachRes = await axios.get(
`https://api.servicem8.com/api_1.0/attachment.json?$filter=job_uuid eq '${jobUuid}'`,
{ headers: authHeaders() }
);
// Filter photos
const photos = attachRes.data.filter(att => att.mime_type?.startsWith("image/"));
// Copy photos to new job
for (const photo of photos) {
const fileBuffer = await axios.get(photo.url, { responseType: "arraybuffer" });
const formData = new FormData();
formData.append("job_uuid", newJobUuid);
formData.append("file", fileBuffer.data, { filename: photo.filename || "photo.jpg" });
await axios.post(
"https://api.servicem8.com/api_1.0/attachment.json",
formData,
{
headers: {
...authHeaders(true),
...formData.getHeaders(),
},
}
);
}
// Fetch notes
const notesRes = await axios.get(
`https://api.servicem8.com/api_1.0/jobcomment.json?$filter=job_uuid eq '${jobUuid}'`,
{ headers: authHeaders() }
);
// Copy notes by keyword
const selectedNotes = notesRes.data.filter(note =>
NOTE_KEYWORDS.some(keyword => note.text.includes(keyword))
);
for (const note of selectedNotes) {
await axios.post(
`https://api.servicem8.com/api_1.0/jobcomment.json`,
{
job_uuid: newJobUuid,
text: note.text,
},
{ headers: authHeaders() }
);
}
When I run this, I get the following error:
Error: {
errorCode: 400,
message: 'jobcomment is not an authorised object type',
documentation: 'Please refer to <https://developer.servicem8.com/llms.txt> for developer documentation.'
}
It looks like jobcomment is not an allowed object type, but I couldn’t find clear documentation on the correct way to transfer notes/comments between jobs.
Questions:
- Is there a supported way to move attachments from one job to another using the API?
- What is the correct object type or endpoint to use for job notes (jobcomment)?
- Is there an official process or recommended approach for linking/duplicating job data (attachments + notes) into a new job?
Thank you for your guidance!