0

I have 2 custom content type. One is movies and the other is actors. I am using REST API POST to add values into movies. Actor is a referential entity within movies. How do I add values into actors which are corresponding to a particular movie when I use POST?

An option that I am currently trying out is add multiple values into actors first and that POST will return a node id, use that node id value along POST values to movies. Is this the right approach?

0

You can see the article about create Custom Rest Resources for POST

You can reference below code below

$node_actor = Node::create(
      ['type' => 'actor',// the content type
        'title' => 'Actor Name',
      ]
    );
   $actor_id = $node_actor->save();

After you can use $actor_id had node reference to movie

$node_movie = Node::create(
   ['type' => 'movie',// the content type
    'title' => 'Movie Name',
   ]
  );
  $node_movie->set('field_actor_ref',['target_id'=>$actor_id])
  $node_movie->save();

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.