cancel
Showing results for 
Search instead for 
Did you mean: 

Dealing with Atlassian object format

runelynx
Deputy Chef II
Deputy Chef II

Hello,

I am having a very tough time figuring out how to work with objects I get from Atlassian's API. Because their objects have so many custom fields, they don't use simple key-value pairs.

As an example, the object within the Values array here represents a specific laptop asset. Within the Attributes array in that object, the laptop's attributes are listed. However I cannot identify attributes programmatically using the attribute names... or even IDs... because of the formatting.

In order to get the "UDID" attribute value for this laptop, I need to find the object within the Attributes array where "Object type attribute ID" = 325. When I find that object, I need to look to the "Object attribute values" array within the object... look at the first object within that array, and use the value associated with the "Value" key.

How on earth can I make this work with Workato? Atlassian has made this SO complicated.

runelynx_0-1702680428529.png

 

1 ACCEPTED SOLUTION

runelynx
Deputy Chef II
Deputy Chef II

Hallelujah!!! Made a few changes to process the larger object containing both arrays... first define the ugly object using IDs but simplifying the ID-Name relationship. Then go back through that object and replace the IDs with names using the 2nd array. 

Thank you @gary1 for the code that got me started!! 

runelynx_0-1702684789488.png

## provide the findIdentifiers array as your "data" input and grab it
inputObject = input["data"]

attributesArray = inputObject["values"][0]["attributes"]
definitionsArray = inputObject["objectTypeAttributes"]

new_object= {}

## loop through findIdentifiers
attributesArray.each { | a | 
  
  new_object[a["objectTypeAttributeId"]] = a["objectAttributeValues"][0]["displayValue"] 
}

## loop through findIdentifiers
definitionsArray.each { | a | 
   ## dig up the type value; this assumes only one object in the Type array 
  typeId = a["id"]
  
  if new_object.has_key?(typeId)
    # Rename "old_key" to "new_key"
	new_key = a["name"]
	old_key_value = new_object.delete(typeId)
	new_object[new_key] = old_key_value
  end
}

## create the output object with itemsToKeep as the value
{result: new_object}

View solution in original post

7 REPLIES 7

javier-riesco
Workato employee
Workato employee

Hey @runelynx , could you share the raw JSON response using the "Copy Raw JSON" button?

javierriesco_0-1702723452278.png

If the response has a fixed schema, it shouldn’t be difficult to retrieve the specific field you need without using Ruby code.

chris-wiechmann
Workato employee
Workato employee

Hi @runelynx

I started a few days ago with a new Jira Assets connector, as I also couldn't believe how people show handle that super-complicated data format Jira Assets is using. I tried to abstract from the underlying technical stuff and make it simple to use the connector. 
Created a short video to show/illustrate how it works: https://youtu.be/0R5aRcAuqdA
Import to note: In order to handle the Object-Type-Schema properly, you have to configure the Object-Type as part of the action.  Depending on the number of object types you have it would required a number of If-Statements, but there is no other around it, as the Schema needs to be know and Config-Time.
Would that be okay for your use-case?

Please let me know your feedback. I'm also happy to share this connector with you once I'm happy with it. 

Cheers,
Chris

chris-wiechmann
Workato employee
Workato employee

Happy new year!
The new Jira Assets connector is now avilable in the community library:
https://app.workato.com/custom_adapters/513076/details?community=true
Please let me know, if this works for your use-case(s) or if you miss anything.

Cheers,
Chris