Skip to main content

Hi,

 

Is it possible to automate creation of relationships as part of a workflow? For example if a user orders a service (not hardware/software) and I would like to track the fact that the user is consuming that service in CMDB for helpdesk to have that insight in case of incident etc.

So I think I solved this on my own by using the bulk create relationship API call. Not really a drag and drop kind of solution that I was looking for but at least it could be done.


Could you share the solution for the community ? 


I will happily share my findings. Please beware that I’m a newbie in terms of Freshservice so it may definitely be other and better solutions for this out there.

I solved this by using a series of the “Web Request” nodes in the workflow. The api for creating relationships only work for agent and requesters separately so before triggering that action I need to find out if the person requesting the service is an agent or not. 

 

Agent or not:

Step 1. Use Web Request node with below settings.

Request type: GET

Endpoint: https://mycronicitsupport.freshservice.com/api/v2/requesters/{{ticket.requester.id}}

Step 2. Use the JSON Parser node and set the Web Request response body as Source.

Step 3. Use a Condition node and use the JSON Parser node to find “requester.is_agent” is “true”

 

Create the relationship:

Create 2 Web Request nodes after the “is_agent” condition.

If the requester is an agent, the web request node can be set as below

Request type: POST

Endpoint: https://mycompany.com/api/v2/relationships/bulk-create

Body: 

{
  "relationships": <
    {
      "relationship_type_id": 52000081231,
      "primary_id": {{ticket.requester.id}},
      "primary_type": "agent",
      "secondary_id": 13,
      "secondary_type": "asset"
    }
  ]
}

 

If the requester is not an agent, the Body would be same but you need to change the type to “requester” as below

Body: 

{
  "relationships": n
    {
      "relationship_type_id": 52000081231,
      "primary_id": {{ticket.requester.id}},
      "primary_type": "requester",
      "secondary_id": 13,
      "secondary_type": "asset"
    }
  ]
}

Note that the “relationship_type_id” is the actual id of the relationship you wish to create while the “secondary_id” is the display id of the asset, not the actual id. To get these id´s I played around with web request (GET) nodes and used “/api/v2/assets” and “/api/v2/relationship_types” as endpoints to find the correct ID´s.

I’ve attached screenshots of the workflow and the resulting relationship created


Reply