My Products
Help
Scruha
CONTRIBUTOR **

How to create a customer group via graphql

by Scruha (Updated ‎15-08-2023 21:45 by Scruha )

Needs to create customer groups and then linked to customers but can't find an API for this. Could someone provide any example or method related to this task?

11 REPLIES 11

by Marius Bancila

The schema is now modified so that you can pass null for all fields that support suggesting value.

omelhus
PARTNER

by omelhus

I'm still getting an error when I try to suggest a textNo.

 

{
  "errors": [
    {
      "message": "A record with the same primary key already exists.",
      "path": [
        "useCompany",
        "text_create",
        "values/0"
      ],
      "extensions": {
        "data": {
          "status": 3
        }
      }
    }
  ],
  "data": {
    "useCompany": {
      "text_create": {
        "items": null
      }
    }
  },
  "extensions": {
    "vbnxt-trace-id": "000000000000000001d1d2d89e53ddfe"
  }
}

by Marius Bancila

This is something else. Previously, you could not set a null, you were getting:

"Argument 'values' has invalid value. In field 'textNo': [Expected 'Long!', found null.]"

Now, you can. The fact that you get a runtime error is a completely different problem.

Scruha
CONTRIBUTOR **

by Scruha

Thank you, as what was needed

Accepted solution
omelhus
PARTNER

by omelhus

Business has multiple ways you can group a customer. Are you thinking CustomerPriceGroup1-3? Or Group1-6? The names for these groups are set in the text-table and you need to add a text with the textType, languageNo, textNo and text. There's no auto-incrementing the textNo unfortunately, so you'll have to grab them all and find the next number yourself.

 

You'll easily find all the correct text types at https://model.vbnxt.rocks/Associate. Below are the groupings on Associate and those with TxtTp are the ones you can add to the text table.

 

omelhus_2-1692172754172.png

 

 

 

omelhus
PARTNER

by omelhus (Updated ‎16-08-2023 10:05 by omelhus PARTNER )

 

mutation createText($cid: Int, $textType: Long!, $textNo: Long!, $text: String!, $language: Int! = 1) {
  useCompany(no: $cid) {
    text_create(
      values: {textType: $textType, languageNo: $language, text: $text, textNo: $textNo}
    ) {
      items {
        textNo
      }
    }
  }
}

 


 Unfortunately suggest for textNo does not work in this mutation. Maybe it should though, @Marius Bancila?

by Marius Bancila

$textNo must be null for a suggest to occur. What are the values of the variables that you pass for the mutation?

omelhus
PARTNER

by omelhus

The schema type of textNo is Long!, so null is not allowed.

 

{
  "errors": [
    {
      "message": "Argument 'values' has invalid value. In field 'textNo': [Expected 'Long!', found null.]",
      "locations": [
        {
          "line": 26,
          "column": 7
        }
      ],
      "extensions": {
        "code": "ARGUMENTS_OF_CORRECT_TYPE",
        "codes": [
          "ARGUMENTS_OF_CORRECT_TYPE"
        ],
        "number": "5.6.1"
      }
    }
  ]
}

by Marius Bancila

OK, then this is a problem. I will investigate what needs to be done here. It probably shouldn't be Long! but just Long. So we might need to update the schema.

Accepted solution
omelhus
PARTNER

by omelhus

Thank you.

 

The correct mutation when this is fixed will then be the following:

 

mutation createText($cid: Int, $textType: Long!, $text: String!, $language: Int! = 1) {
  useCompany(no: $cid) {
    text_create(
      values: {textType: $textType, textNo: null, languageNo: $language, text: $text}
      suggest: {textNo: true}
    ) {
      items {
        textNo
      }
    }
  }
}

 

Accepted solution
Marius Bancila
VISMA

by Marius Bancila

That should work, unless there is a different order of the fields that is required by the particular business logic here, and textNo can't be the last one provided. But if you ran it and it works then it's all good (for now).