Migrating a content type from D7 into a greenfield D8 app, so I'm using Subrequests and jsonapi modules. My first subrequest to create a simple Paragraph returns the new ID and it properly replaces my token in my node--person, until it gets wiped out at some point within the many calls to httpKernel->handle($request) class. I've burned a few hours setting breakpoints to see how its losing the replaced Paragraph ID but I've not mastered the Symfony Http system.

I've tried adding an owner iid, attempted to derive a "meta" array for a target_revision_id from the drupal_internal_revision_id property but that returns a 500 error. Here's a minimized code of the blueprint.

function bodyPerson($person){$data = ["data" =>
      ['type' => 'node--person',
       'attributes' =>
        ['title' => 'ignored',
        'status' =>"1",
        'field_body' =>
          ['value' => 'Highlights.', 
            'format' => 'full_html', 
            'summary' => ''],
       'field_last_name' => 
       'owner' => ['data' =>
         ['type' => 'user--user',
         'id' => '2061b881-d5ea-4daa-a006-616e47xxx']],
       'field_title' =>['data' =>
         ['type' => "paragraph--title",
           'id' => "{{paragraph-title-1.body@$.data.id}}"]
      return $data;
     $bodyp = json_encode(["data" => ['type' => 'paragraph--title', 
      'attributes' => ['field_department' => ['value' => "my dept 1a"]], 
      ['field_title' => ['value' => "my title 1a"]]]]
     $blueprint = json_encode([['action' => 'create', 'requestId' =>    'paragraph-title-1', 'body' => $bodyp, 'uri' => '/jsonapi/paragraph/title', 'headers' => $headers], ['action' => 'create', "waitFor" => ["paragraph-title-1"], "requestId" => "person-test", 'headers' => $headers, 'uri' => "/jsonapi/node/person", 'body' => $bodyPer]]);

Passing the $blueprint and the two body blocks into curl returns the new Paragraphs object, passing it to the final POST subrequest. The result is an empty "data" array where the Paragraphs' link should be.

            "field_title": {
                "data": [],
                "links": {
                    "self": {
                        "href": "\/jsonapi\/node\/person\/9ebcdd24-d8ee-428d-8770-1ad62eexx\/relationships\/field_title?resourceVersion=id%3A1045"
                    "related": {
                        "href": "\/jsonapi\/node\/person\/9ebcdd24-d8ee-428d-8770-1ad62exx\/field_title?resourceVersion=id%3A1045"

Subrequests is working for other subrequests in this body.

Adding more context into this issue. Subrequests are generally working, except where the final parent node is able to save with the UUID of the early subrequests to attach using relationships newly-created entities, like this Paragraph. Able to save an image into file--file but the parent node loses the UUID of the entity in Drupal. Spending hours walking through the process through HttpKernel the JSON, or the UUID, survives as a content attribute in several Request objects. It seems to get lost being saved as an Entity. As you know, the Paragraphs entity is an EntityReferenceRevisions object, but still part of the Entity API, it seems. It appears that the parent node loses the target_id of the saved Paragraphs entity while going through the steps to save a node. Notably the ContentEntityBase::updateOriginalValues() where it's attempting to filter out empty fields. Perhaps the Entity system is looking elsewhere for the target_id? The JSON returned when the Paragraph is instantiated returns its UUID. That should be a reference to the entity's attributes like paragraphs_item_revision vid, like the paragraphs_item nid? I'm unsure how to prep this object so that it can be linked to its parent node without jsonapi and subrequest's help.

  • sam452 have u solved it? – rebeling Jun 25 at 14:39
  • Sadly, no. I gave up and used this approach to Entity class: Paragraph::create([array of properties]). Then using returned paragraph entity to set its target_id, target_revision_id to my parent Node. Knowing that, creating Paragraph in jsonapi does NOT return an explicit revision_id in UUID. Assigning Paragraph requires id and revision_id. So I can't see how it would work without revision_id in UUID. – sam452 Jun 25 at 16:39
  • Yeah, just means jsonapi can do everything, but not paragraphs ...crazy. At the moment I am trying to add nodes with images via the jsonapi and I am not sure if anybody ever get it done in RL. – rebeling Jun 25 at 19:06

Your Answer

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

Browse other questions tagged or ask your own question.