Skip to main content
Solved

GQL queries with attributes

  • August 21, 2024
  • 4 replies
  • 0 views

Forum|alt.badge.img

We have a need to automate lots of BSM service creations and I am struggling with GQL now.

We have created attribute to be used for har

query {customAttributes
  (first: 7, search: {name: {eq: "BSM_Region"}})
  {
  edges {
    node {id label type entity alignmentType
        }
        }
    }
}

and that gives us: 

{
  "data": {
    "customAttributes": {
      "edges": [
        {
          "node": {
            "id": "57",
            "label": "BSM_Region",
            "type": "string",
            "entity": "harProvider",
            "alignmentType": "extended"
          }
        }
      ]
    }
  }
}

If I then try to align that attribute to spesific service like this:

mutation {alignCustomAttribute(
  attribute:57, 
  entity: "cm03r2q3a807hs5mn8m4a1dga",
  value:"Koillismaan kauppa", 
  type: harProvider
)
  {__typename}
}

It gives an error:

{
  "errors": [
    {
      "path": [
        "alignCustomAttribute"
      ],
      "message": "The following id/ids: 57 could not be found. Failed to align custom attributes.",
      "extensions": {
        "code": "ID_NOT_FOUND"
      }
    }
  ],
  "data": {
    "alignCustomAttribute": null
  }
}

Some help needed here.

 

Best answer by teppotahkapaa

OK, solution found.

Against documentation in /gql, when you utilize SL1 attribute information the "id" is not the ID that is mentioned in docs, and everywhere else it is the DID,GUID etc, but in this context it points to name,

So actually here we needed to use it this way:

  type:harProvider
    attributes: {
    id:"BSM_Region"
    value:"Koillismaan kauppa"
  }, 

Thanks @jchivers for info!

4 replies

  • Community Manager
  • August 22, 2024

Hi Teppo,

 I am working on an answer for you. Back soon. 


Forum|alt.badge.img

Same error with the other GQL

mutation {alignCustomAttributes(
  entity:"cm0apy4718wlbscmn74v7g943", 
  type:harProvider
    attributes: {
    id:"57"
    value:"Koillismaan kauppa"
  }, 
  
)
  {__typename}
}


Forum|alt.badge.img
  • Author
  • Leader
  • Answer
  • August 27, 2024

OK, solution found.

Against documentation in /gql, when you utilize SL1 attribute information the "id" is not the ID that is mentioned in docs, and everywhere else it is the DID,GUID etc, but in this context it points to name,

So actually here we needed to use it this way:

  type:harProvider
    attributes: {
    id:"BSM_Region"
    value:"Koillismaan kauppa"
  }, 

Thanks @jchivers for info!


  • Community Manager
  • August 27, 2024

Hello Teppo,

here is the correct GQL to 1) retrieve a list of available Custom Attributes of type HARProvider, and 2) align an attribute to a service

Get a list of extended attributes for services

query serviceDetailsGetAllCustomAttributes(
  $first: Int
  $after: String
  $search: CustomAttributeSearch
  $isGlobalManagerRequest: Boolean
  $globalManagerStackSearch: GlobalManagerStackSearch
) {
  customAttributes(
    search: $search
    first: $first
    after: $after
    isGlobalManagerRequest: $isGlobalManagerRequest
    globalManagerStackSearch: $globalManagerStackSearch
  ) {
    edges {
      node {
        id
        label
        type
        alignmentType
        name
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}
Query Variables

{
  "first": 30,
  "search": {
    "and": [
      {
        "alignmentType": {
          "eq": "extended"
        }
      },
      {
        "entity": {
          "eq": "harProvider"
        }
      },
      {
        "label": {
          "contains": ""
        }
      }
    ]
  },
  "isGlobalManagerRequest": false,
  "globalManagerStackSearch": {}
}
 

Align an attribute to a service

mutation serviceDetailsAlignCustomAttributes(
  $serviceId: ID!
  $bulkAttributes: [CustomAttributeIdValueInput!]
) {
  alignCustomAttributes(
    attributes: $bulkAttributes
    entity: $serviceId
    type: harProvider
  ) {
    ...serviceDetailCustomAttribute
  }
}
 
fragment serviceDetailCustomAttribute on AlignedCustomAttribute {
  ... on CustomIntAttribute {
    id
    label
    intval: value
    type
    alignmentType
  }
  ... on CustomStringAttribute {
    id
    label
    value
    type
    alignmentType
  }
}
Query Variables

{
  "serviceId": "u8o37motye647x35i5u8w14v",
  "bulkAttributes": [
    {
      "id": "BDS_20_Extended_20_String",
      "value": "BDS CS 1"
    }
  ]
}