Call users.labels.list for the mailbox and save the name to id mapping. Expected: every label you plan to use appears with an id.

Check whether you passed a display name such as a folder name in place of an id. Expected: names with spaces or custom casing are the usual mismatch.

If the label is absent from the list, create it with users.labels.create before modifying messages. Expected: the create call returns the new label id.

Rebuild the batchModify body using only ids from step 1 or 3 in addLabelIds and removeLabelIds. Expected: no display names remain in the request.

Retry batchModify on a single message first. Expected: a 204 or empty success response, then apply it to the full batch.