Total unique constraints per object type

Vladimír Richter
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 10, 2025

How to find with Object Type in Assets has Total unique constraints per object type higher then 2?

4 answers

1 vote
Prasad Bonthu March 12, 2025

Designing a workflow in Postman requires significant time, effort, and experience. To simplify the process, I have written a Bash script that produces the same results.



#!/bin/bash

# Set API details
WORKSPACE_ID="your-workspace-id" # Replace with your Atlassian workspace ID
API_TOKEN="your-api-token"

# Atlassian Assets API Base URL
BASE_URL="https://api.atlassian.com/jsm/assets/workspace/$WORKSPACE_ID/v1"

# Headers for authentication
AUTH_HEADER="-H Authorization: Bearer $API_TOKEN"
CONTENT_HEADER="-H Content-Type: application/json"

# Temporary file to store results
OUTPUT_FILE="unique_attribute_counts.csv"
echo "ObjectTypeID,ObjectTypeName,UniqueCount" > "$OUTPUT_FILE"

# Fetch object schemas
SCHEMAS=$(curl -s -X GET "$BASE_URL/objectschema/list" $AUTH_HEADER $CONTENT_HEADER)

# Validate if SCHEMAS is valid JSON
if ! echo "$SCHEMAS" | jq empty 2>/dev/null; then
echo "Error: Invalid JSON response from object schemas API."
exit 1
fi

# Extract schema values
SCHEMAS=$(echo "$SCHEMAS" | jq -c '.values[]')

# Loop through each schema
echo "$SCHEMAS" | while IFS= read -r SCHEMA; do
SCHEMA_ID=$(echo "$SCHEMA" | jq -r '.id')

# Fetch object types for this schema
OBJECT_TYPES=$(curl -s -X GET "$BASE_URL/objectschema/$SCHEMA_ID/objecttype/list" $AUTH_HEADER $CONTENT_HEADER)

# Validate if OBJECT_TYPES is valid JSON
if ! echo "$OBJECT_TYPES" | jq empty 2>/dev/null; then
echo "Warning: Invalid JSON response for schema ID $SCHEMA_ID."
continue
fi

# Extract object types
OBJECT_TYPES=$(echo "$OBJECT_TYPES" | jq -c '.values[]')

echo "Processing schema ID: $SCHEMA_ID"

# Loop through each object type
echo "$OBJECT_TYPES" | while IFS= read -r OBJ_TYPE; do
OBJ_TYPE_ID=$(echo "$OBJ_TYPE" | jq -r '.id')
OBJ_TYPE_NAME=$(echo "$OBJ_TYPE" | jq -r '.name')

# Fetch attributes for this object type
ATTRIBUTES=$(curl -s -X GET "$BASE_URL/objecttype/$OBJ_TYPE_ID/attributes" $AUTH_HEADER $CONTENT_HEADER)

# Validate if ATTRIBUTES is valid JSON
if ! echo "$ATTRIBUTES" | jq empty 2>/dev/null; then
echo "Warning: Invalid JSON response for Object Type ID: $OBJ_TYPE_ID"
UNIQUE_COUNT=0
else
# Extract attributes and check uniqueAttribute
UNIQUE_COUNT=$(echo "$ATTRIBUTES" | jq '[.values[] | select(.uniqueAttribute == true)] | length')
fi

echo "Object Type: $OBJ_TYPE_NAME (ID: $OBJ_TYPE_ID) - Unique Attributes: $UNIQUE_COUNT"

# Store results
echo "$OBJ_TYPE_ID,$OBJ_TYPE_NAME,$UNIQUE_COUNT" >> "$OUTPUT_FILE"
done
done

echo "Processing complete. Results saved to $OUTPUT_FILE."



 

Prasad Bonthu March 12, 2025

To Fetch workspace, use below request

https://<JSM Premium Site Name>.atlassian.net/rest/servicedeskapi/assets/workspace

Like sciencecovskij likes this
Marc - Devoteam
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2025

Hi @Prasad Bonthu 

Can you share the postman workflow?

1 vote
Prasad Bonthu March 12, 2025

I have designed a workflow in Postman using the Assets REST API to retrieve and display the count of unique attributes from each schema, as shown in the image below. The logic remains the same.
image.png

sciencecovskij March 12, 2025

Nice. 

Like Prasad Bonthu likes this
0 votes
Pier-Olivier Tremblay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2025
0 votes
sciencecovskij March 10, 2025

You can do it manually, but this may be a tedious task: you have to select each single attribute of an object type definition and check "three dots"->Configuration->General whether the "unique" checkbox is checked (= unique constraint) or not. If more than two attributes have been marked as unique, you have to uncheck at least one.

I have written a program (using C#, legacy .NET Framework 4.8; should work with modern .NET as well) against the Assets REST-API (The Assets REST API). First, the app reads and stores all available schemes (use GET .../objectschema/list). Then, it extracts for each schema all object types (use GET .../objectschema/{id}/objecttypes) and stores them in lists (actually, you just need the id and the name for each object type). Then, it reads the list of object type attributes für each object type (use GET .../objecttype/{id}/attributes). Finally, it loops through these lists and sums up (for each object type) the number of cases where the value of the "uniqueAttribute" is true.   

In my case, the result looks like this (I could have listed the "unique" attributes as well, but it was not required in our case; however, if your object types are rather big, this might still be useful):


unique_check.png

Prasad Bonthu March 12, 2025

Clean and simple way.

Like sciencecovskij likes this
sciencecovskij March 12, 2025

Some people at my institute were quite confused when the email from Atlassian came up raising the issue. The program identified the unique constraints in question and the problem was quickly resolved.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events