Forum Discussion

teppotahkapaa's avatar
4 months ago

GQL queries with attributes

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.

 

  • 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!

  • 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"
        }
      ]
    }

  • 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!

  • Same error with the other GQL

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