<p>Two things, I see a typo in your variables (extra <code>,</code> after <code>&quot;headline&quot;: &quot;test&quot;,</code>), and you should be passing an <code>id</code> to the block, not <code>sortOrder</code> (<a href="https://craftcms.com/docs/4.x/graphql.html#matrix-fields-in-mutations" rel="nofollow noreferrer">see docs</a>). Try the below as variables and it should work:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;title&quot;: &quot;test&quot;,
    &quot;info&quot;: &quot;info&quot;,
    &quot;authorId&quot;: 1,
    &quot;siteId&quot;: 2,
    &quot;sortOrder&quot;: [
        &quot;new1&quot;
    ],
    &quot;biography&quot;: [
        {
            &quot;biosection&quot;: {
                &quot;id&quot;: &quot;new1&quot;,
                &quot;headline&quot;: &quot;test&quot;
            }
        }
    ]
}
</code></pre>

CC BY-SA 4.0
2024-02-22T08:46:53.340Z
2024-02-22T08:46:53.340Z
Oli
<p>I'm trying to write a GraphQL query which creates matrix blocks. The information in the docs as well as <a href="https://craftcms.stackexchange.com/questions/39020/creating-an-entry-with-a-matrix-field-using-graphql">this question</a> didn't help to get it working.</p>
<p>This is what the field settings look like:
<a href="https://i.sstatic.net/mgnOW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mgnOW.png" alt="enter image description here" /></a></p>
<p>This is my query:</p>
<pre><code>mutation saveEntry(
    $biography: [biography_MatrixBlockContainerInput]
    $sortOrder: [QueryArgument]
    $info: String
    $authorId: ID
    $siteId: Int
    $title: String
) {
    save_artist_default_Entry(
        biography: { blocks: $biography, sortOrder: $sortOrder }
        info: $info
        authorId: $authorId
        siteId: $siteId
        title: $title
    ) {
        id
        title
        info
    }
}
</code></pre>
<p>And here my variables:</p>
<pre><code>{
    &quot;title&quot;: &quot;test&quot;,
    &quot;info&quot;: &quot;info&quot;,
    &quot;authorId&quot;: 1,
    &quot;siteId&quot;: 1,
    &quot;sortOrder&quot;: [
        &quot;new1&quot;
    ],
    &quot;biography&quot;: [
        {
            &quot;biosection&quot;: {
                &quot;sortOrder&quot;: &quot;new1&quot;,
                &quot;headline&quot;: &quot;test&quot;,
            }
        }
    ]
}
</code></pre>
<p>When using <a href="https://insomnia.rest/" rel="nofollow noreferrer">Insomnia</a> (API client) to test the query, I get the following error:</p>
<pre><code>{
    &quot;errors&quot;: [
        {
            &quot;message&quot;: &quot;craft\\services\\Gql::executeQuery(): Argument #3 ($variables) must be of type ?array, string given, called in /Users/xxx/vendor/craftcms/cms/src/controllers/GraphqlController.php on line 195&quot;
        }
    ]
}
</code></pre>
<p>I don't know why it says Argument #3 causes the error. I changed the order but the error message never changes.
If I remove the &quot;biography&quot; block from the variables, it works.</p>

<graphql>
Using a GraphQL mutation query to create matrix blocks
# Using a GraphQL mutation query to create matrix blocks

(Asked by: username_0 on 2024-02-19)

I'm trying to write a GraphQL query which creates matrix blocks. The information in the docs as well as this question didn't help to get it working.
This is what the field settings look like:

This is my query:
mutation saveEntry(
    $biography: [biography_MatrixBlockContainerInput]
    $sortOrder: [QueryArgument]
    $info: String
    $authorId: ID
    $siteId: Int
    $title: String
) {
    save_artist_default_Entry(
        biography: { blocks: $biography, sortOrder: $sortOrder }
        info: $info
        authorId: $authorId
        siteId: $siteId
        title: $title
    ) {
        id
        title
        info
    }
}

And here my variables:
{
    "title": "test",
    "info": "info",
    "authorId": 1,
    "siteId": 1,
    "sortOrder": [
        "new1"
    ],
    "biography": [
        {
            "biosection": {
                "sortOrder": "new1",
                "headline": "test",
            }
        }
    ]
}

When using Insomnia (API client) to test the query, I get the following error:
{
    "errors": [
        {
            "message": "craft\\services\\Gql::executeQuery(): Argument #3 ($variables) must be of type ?array, string given, called in /Users/xxx/vendor/craftcms/cms/src/controllers/GraphqlController.php on line 195"
        }
    ]
}

I don't know why it says Argument #3 causes the error. I changed the order but the error message never changes.
If I remove the "biography" block from the variables, it works.

**Tags:** graphql

---

## 1 answers

### Answer by username_1 on 2024-02-22. Score: 2 | Accepted answer

Two things, I see a typo in your variables (extra , after "headline": "test",), and you should be passing an id to the block, not sortOrder (see docs). Try the below as variables and it should work:
{
    "title": "test",
    "info": "info",
    "authorId": 1,
    "siteId": 2,
    "sortOrder": [
        "new1"
    ],
    "biography": [
        {
            "biosection": {
                "id": "new1",
                "headline": "test"
            }
        }
    ]
}


---

