Question

Having trouble with API Response Body

  • 30 September 2022
  • 9 replies
  • 299 views

Userlevel 3
Badge +4

When I run a GET webhook in our workflow automator using the following API call:

 

https://domain.freshservice.com/api/v2/assets?filter=%22user_id%3A%20120001632022%22

 

The response body is not neatly broken up and is returned as a single string.

 

{  "assets": "[{\"id\": 75000886025, \"display_id\": 893, \"name\": \"189\", \"description\": null, \"asset_type_id\": 75000416033, \"impact\": \"low\", \"author_type\": \"User\", \"usage_type\": \"permanent\", \"asset_tag\": \"ASSET-893\", \"user_id\": 120001632022, \"department_id\": null, \"location_id\": null, \"agent_id\": null, \"group_id\": null, \"assigned_on\": \"2018-01-02T16:00:00Z\", \"created_at\": \"2022-07-12T03:31:39Z\", \"updated_at\": \"2022-07-12T03:31:39Z\", \"end_of_life\": null}, {\"id\": 75000878611, \"display_id\": 374, \"name\": \"656\", \"description\": null, \"asset_type_id\": 75000416027, \"impact\": \"low\", \"author_type\": \"Discovery Agent\", \"usage_type\": \"permanent\", \"asset_tag\": \"ASSET-374\", \"user_id\": 120001632022, \"department_id\": null, \"location_id\": null, \"agent_id\": null, \"group_id\": null, \"assigned_on\": \"2019-01-02T16:00:00Z\", \"created_at\": \"2022-07-05T04:21:07Z\", \"updated_at\": \"2022-09-30T00:10:25Z\", \"end_of_life\": null}]"}

 

I need to be able to use the information contain from the response in subsequent workflow nodes. Would really appreciate someone pointing out what I am doing wrong!

Cheers.


9 replies

Userlevel 7
Badge +13

When I run a GET webhook in our workflow automator using the following API call:

 

https://domain.freshservice.com/api/v2/assets?filter=%22user_id%3A%20120001632022%22

 

The response body is not neatly broken up and is returned as a single string.

 

{  "assets": "[{\"id\": 75000886025, \"display_id\": 893, \"name\": \"189\", \"description\": null, \"asset_type_id\": 75000416033, \"impact\": \"low\", \"author_type\": \"User\", \"usage_type\": \"permanent\", \"asset_tag\": \"ASSET-893\", \"user_id\": 120001632022, \"department_id\": null, \"location_id\": null, \"agent_id\": null, \"group_id\": null, \"assigned_on\": \"2018-01-02T16:00:00Z\", \"created_at\": \"2022-07-12T03:31:39Z\", \"updated_at\": \"2022-07-12T03:31:39Z\", \"end_of_life\": null}, {\"id\": 75000878611, \"display_id\": 374, \"name\": \"656\", \"description\": null, \"asset_type_id\": 75000416027, \"impact\": \"low\", \"author_type\": \"Discovery Agent\", \"usage_type\": \"permanent\", \"asset_tag\": \"ASSET-374\", \"user_id\": 120001632022, \"department_id\": null, \"location_id\": null, \"agent_id\": null, \"group_id\": null, \"assigned_on\": \"2019-01-02T16:00:00Z\", \"created_at\": \"2022-07-05T04:21:07Z\", \"updated_at\": \"2022-09-30T00:10:25Z\", \"end_of_life\": null}]"}

 

I need to be able to use the information contain from the response in subsequent workflow nodes. Would really appreciate someone pointing out what I am doing wrong!

Cheers.

Where do you see this? 
Looks like something that can’t read JSON correct. 

 

//Daniel 

Userlevel 3
Badge +4

Hi Daniel,

This is how it appears in the execution logs of the workflows I have run with that particular webhook in there.

 

Other nodes that use GET return a response body that you would expect as well within the same workflow.

Userlevel 7
Badge +13

Hi Daniel,

This is how it appears in the execution logs of the workflows I have run with that particular webhook in there.

 

Other nodes that use GET return a response body that you would expect as well within the same workflow.

You need to use the webrequest node and in that you can run a test where you get the correct JSON respons.  Then you can use the outout from the WR-node in the JSON parser node. 

Userlevel 7
Badge +16

Yup have to agree with @daniel.soderlund, you just need to parse the JSON response and then you can access the data that you need later in your workflow. :)

Userlevel 3
Badge +4

Sorry I should have specified but the data is dynamic and will have a new value everytime the workflow runs. As I understand it, the response body needs to return in correct JSON formatting to be able to parse correctly. I will try do a better illustration of the issues I am having.

The workflow makes the following GET call using the WR-node with a dynamic requester ID based on information from the ticket.

https://linkforce.freshservice.com/api/v2/assets?filter=%22user_id%3A%20{{P8.root.requester.id}}%22

 

When testing a Requester ID within the workflow, the response body of the data appears as expected:

I then use the Parser node to get the fields I want to reference in another WR-Node further along the workflow. 

However when the workflow is run when using the event triggers I have set up. The response body is returned in square brackets [response_body] making it so I can not select the specific fields I need in the subsequent WR-nodes in the same workflow.

This is how it plays out:
 

 

I am hoping to find out what have I done to make it so when the workflow is triggered I get a single string response with the GET call I make earlier. Earlier in the same workflow, I am able to make a GET call, return the correct response, and parse it to use that information.

Really appreciate your help guys!

Userlevel 7
Badge +13

Hi, @MichaelS24 

You shouldn’t use the data from the execution logs. 

The respons you get in W11 you paste in to P9 and click Generate Output and save the node. 
That should be all you need to do. 


If you add a note to the ticket after the W11 with the respons body placeholder how does that look? 
You can add note after the P9 as well with the placeholders you wish to use to check. 

//Daniel 

Userlevel 7
Badge +16

Hi @MichaelS24 This tripped me up at first as well. But @daniel.soderlund is right. You should make sure that you are generating an output with the JSON parser for each data source you use in the workflow, simply because not all responses are formatted the same way.

Userlevel 3
Badge +4

The image of the formatting used from the failed response was never actually used in my workflows, just to illustrate my thought process. I was tripped up because the fields I ended up referencing further along actually weren’t showing in my tests - a mistake I made.

It is working as expected now after some more tests. Thank you very much @daniel.soderlund and @zachary.king for your speedy feedback and helpful advice!

Userlevel 7
Badge +16

The image of the formatting used from the failed response was never actually used in my workflows, just to illustrate my thought process. I was tripped up because the fields I ended up referencing further along actually weren’t showing in my tests - a mistake I made.

It is working as expected now after some more tests. Thank you very much @daniel.soderlund and @zachary.king for your speedy feedback and helpful advice!

Glad you were able to get it figured out!

Reply