<p>Try this:</p>
<pre class="lang-graphql prettyprint-override"><code>mutation SaveVehicle($vehicles: [vehicles_MatrixBlockContainerInput], $sortOrder: [QueryArgument]) {
  save_applications_application_Entry(vehicles: {blocks: $vehicles, sortOrder: $sortOrder}) {
        uid
        vehicles {
            ...on vehicles_vehicle_BlockType {
                vehicleValue
            }
        }
    }
}
</code></pre>
<p>And your variables:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;sortOrder&quot;:&quot;new1&quot;,
    &quot;vehicles&quot;: [
        {
            &quot;vehicle&quot;: {
                &quot;id&quot;: &quot;new1&quot;, 
                &quot;vehicleValue&quot;: &quot;111&quot;
            }
        }
    ]
}
</code></pre>
<p>You can find more info <a href="https://craftcms.com/docs/3.x/graphql.html#matrix-fields-in-mutations" rel="nofollow noreferrer">in the documentation</a>.</p>

CC BY-SA 4.0
2022-02-10T20:51:29.140Z
Thank you very much, this is exactly what I needed! Works perfectly.
theboldben
CC BY-SA 4.0
2022-02-09T14:39:10.403Z
2022-02-09T14:39:10.403Z
Oli
<p>I am trying to create a new entry in Craft CMS using GraphQL. The entry has a matrix field called &quot;vehicles&quot; that has a single block called &quot;vehicle&quot;. This block has a single field called &quot;vehicleValue&quot;.</p>
<p><a href="https://i.sstatic.net/jncw5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jncw5.png" alt="enter image description here" /></a></p>
<p>In GraphiQL I am using the following query to save a new entry:</p>
<pre><code>mutation SaveVehicle($vehicles: vehicles_MatrixInput) {
  save_applications_application_Entry(vehicles: $vehicles) {
    uid
    vehicles {
      ... on vehicles_vehicle_BlockType {
        vehicleValue
      }
    }
  }
}
</code></pre>
<p>Then I pass the following variables:</p>
<pre><code>{
  &quot;vehicles&quot;: {
    &quot;blocks&quot;: [
      {
        &quot;vehicle&quot;: {
          &quot;vehicleValue&quot;: 111
        }
      }
    ]
  }
}
</code></pre>
<p>The query runs and a new entry is created but the matrix field is empty.</p>
<p>The schema is public so no auth is required.</p>
<p>I am new to using Craft and GraphQL so it is probably something simple. Any help would be greatly appreciated.</p>

<craft3><matrix><graphql>
Creating an entry with a matrix field using GraphQL
# Creating an entry with a matrix field using GraphQL

(Asked by: username_0 on 2022-02-08)

I am trying to create a new entry in Craft CMS using GraphQL. The entry has a matrix field called "vehicles" that has a single block called "vehicle". This block has a single field called "vehicleValue".

In GraphiQL I am using the following query to save a new entry:
mutation SaveVehicle($vehicles: vehicles_MatrixInput) {
  save_applications_application_Entry(vehicles: $vehicles) {
    uid
    vehicles {
      ... on vehicles_vehicle_BlockType {
        vehicleValue
      }
    }
  }
}

Then I pass the following variables:
{
  "vehicles": {
    "blocks": [
      {
        "vehicle": {
          "vehicleValue": 111
        }
      }
    ]
  }
}

The query runs and a new entry is created but the matrix field is empty.
The schema is public so no auth is required.
I am new to using Craft and GraphQL so it is probably something simple. Any help would be greatly appreciated.

**Tags:** craft3, matrix, graphql

---

## 1 answers

### Answer by username_1 on 2022-02-09. Score: 1 | Accepted answer

Try this:
mutation SaveVehicle($vehicles: [vehicles_MatrixBlockContainerInput], $sortOrder: [QueryArgument]) {
  save_applications_application_Entry(vehicles: {blocks: $vehicles, sortOrder: $sortOrder}) {
        uid
        vehicles {
            ...on vehicles_vehicle_BlockType {
                vehicleValue
            }
        }
    }
}

And your variables:
{
    "sortOrder":"new1",
    "vehicles": [
        {
            "vehicle": {
                "id": "new1", 
                "vehicleValue": "111"
            }
        }
    ]
}

You can find more info in the documentation.

> **Comments:**
> **username_0**: Thank you very much, this is exactly what I needed! Works perfectly.  

---

