How to find with Object Type in Assets has Total unique constraints per object type higher then 2?
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."
To Fetch workspace, use below request
https://<JSM Premium Site Name>.atlassian.net/rest/servicedeskapi/assets/workspace
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you share the postman workflow?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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):
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.