I have a headless Drupal 8 and want to create a translation for an existing NODE using a POST request but cannot figure how to.

I know how to create, edit and delete a node but am unsure on how to add a translation to an existing node. If I add the langcode it creates a new node in that specified language but I want a translation for an existing node ID.

Please advise.


You have to load the node first and than addTranslation. You can check if exists or not. This way I was able to do it.

    $transNode = Node::load($nid);
    $transNode = $transNode->addTranslation("en");
    $transNode->title = $title_EN;
    $transNode->body= $body_EN;
    $transNode->field_1 = $field_1_EN;
| improve this answer | |
  • After a bit of more research. Your response is correct. REST does not support adding translations so I actually had to create a custom endpoint, load the node and add a translation using a variation of the above code. – Lia Jul 3 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.