Happy Business Starts Here

Parsing input JSON in a Workflow

Highlighted
Valued Scholar

Parsing input JSON in a Workflow

Folks,

I am working on a workflow, where i need to query the additional columns for a given set of subscriptions and return the result in a JSON response.

Here's my input JSON attached in the body

 

{
"Subscription":[
{
"Id":"2c92c0f9709f71c60170a7aba29f42af"
},
{
"Id":"2c92c0f8709f61890170a7ac2d7e7440"

}
]

 

I am trying to parse this JSON and get it stored in the workflow and use it in a Data Query.

I am using Logic:JSONTransform for this, but i am not able to parse the input JSON.

Here are the task details,

{
"workflow": {
"id": 22607,
"name": "",
"description": "",
"parameters": {
},
"data": {
},
"original_workflow_id": null,
"type": "Workflow:Smiley Frustratedetup",
"ondemand_trigger": true,
"callout_trigger": true,
"scheduled_trigger": false,
"interval": null,
"timezone": null,
"status": null,
"finished_at": null,
"css": {
"top": "40px",
"left": "35px"
},
"notifications": {
},
"started_at": null,
"call_type": "ASYNC",
"priority": "Medium",
"sync_trigger": false,
"run_mode": "automated",
"delete_ttl": 60,
"task_summary": {
}
},
"tasks": [
{
"id": 46674,
"name": "Parse Input JSON",
"parameters": {
"template": "{\r\n \"SubscriptionId\"Smiley Frustratedubscription.Id\r\n}",
"placement": "JSONTransform",
"processor": "JSONata",
"csv_headers": "\"SubscriptionId\"\r\n",
"replace_payload": "true",
"strict_variables": "true"
},
"action_type": "Logic::JSONTransform",
"object": null,
"object_id": null,
"call_type": "SOAP",
"task_id": null,
"original_task_id": null,
"original_workflow_id": null,
"status": null,
"error": null,
"error_details": null,
"process_id": null,
"css": {
"top": "10px",
"left": "360px"
},
"concurrent_limit": 9999999,
"iterate_row_reference": null,
"error_class": null,
"object_batched_reference": null,
"tags": [
""
],
"priority": "Medium",
"assignment": [

]
}
],
"linkages": [
{
"source_workflow_id": 22607,
"source_task_id": null,
"target_task_id": 46674,
"linkage_type": "Finish"
}
]
}

 

Any pointers on how to do this?

Thanks,

Vimal

7 REPLIES 7
Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@vkannan Which workflow object is this JSON stored in?

 

If it is stored in the Subscription object, use can form your Jsonata as:

(
$.Subscription.Id

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@arindamkesh the JSON is the input from the calling application, in our case we have a web application that has the list of Subscription IDs and wants to get details around terms, status etc back from Zuora and i am thinking of using the Workflow to get the input IDs, convert it as an input to a Data Query and send the response as a JSON back.

 

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@vkannan I will assume that you have created 1 parameter (say JSONInput) in the Workflow, which is supposed to contain a JSON message, for example:

 

{
"Subscription":[
{
"Id":"2c92c0f9709f71c60170a7aba29f42af"
},
{
"Id":"2c92c0f8709f61890170a7ac2d7e7440"
}
]
}

 

This can be accessed/parsed in a JSONTranform activity using the following JSONata (say Payload Placement = SubscriptionArray):

(
	$.Workflow.JSONInput.Subscription.Id
) 

This would create an array of Subscription Ids in SubscriptionArray, and you can refer to them using SubscriptionArray[0] & SubscriptionArray[1]

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@arindamkesh thanks for the pointers, i am now able to see the IDs as an array in the SubscriptionArray field. The question is how do i use them to query the Subscription Object?

My requirement is to iterate over the subscription object and return the Name for each of the subscription based on the ID.

For example, my output JSON should be something like this,

"Details"[{

"Name":"A-S00000434"

},

{

"Name":"A-S00000454"

}] 

 

Thanks,

Vimal

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@vkannan You can add an Iterate activity after the JSONTransform. In that Iterate, use CUSTOM LIQUID {{ Data.SubscriptionArray | to_json }}

On doing a For Each on that Iterate, you will have access to each Id in {{ Data.SubscriptionArray }}. You can use that in your Object Query.

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@arindamkesh the issue is i don't want to iterate one ID at a time, i am trying to get one JSON with the details of the all the subscription IDs.

Thanks,

Vimal

Highlighted
Valued Scholar

Re: Parsing input JSON in a Workflow

@vkannan Sorry, not sure how to do that. Maybe you can get a list of all relevant subscriptions by running a Data Query (datalink), store it as JSON and use JSONata to map your array of Ids to Names.