Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Send post in java with custom steps and labels



this is more of a JSON question in Java rather than a TestRail question, but I hope to find also an answer.

I have a custom filed calles ‘Labels’ (system name ‘tags’) that is a multi-select field.
I also have the custom_steps_separated configured.

Both fields I like to set via an api call, but my problem is that I have no idea how to set up my data map.

Map<String, Object> dataMap = new HashMap<>();
dataMap.put("title", title);
dataMap.put("custom_preconds", precondition);
dataMap.put("custom_tags", ???);

What type/datastructure must be used for modelling the tags and the custom steps ?

and the key for the steps is custom_steps_separated - what is it for the expected results ? custom_expected_results


400 Bad Request, response on when creating a new test run from API call
API Adding Test cases using JAVA

Hello Andreas,

Thanks for your posting! The custom_steps_separated field expects an array of steps, each with the step description (content), expected result (expected) and optionally actual result (actual) and status (status_id) fields. You can find the raw JSON representation here:

(expand Request example)

To map this to Java, you would need to use a combination of List and Map objects and this can look as follows, for example:

Map step1 = new HashMap();
step1.put("status_id", new Integer(5));
step1.put("content", "Step description 1");
step1.put("expected", "Expected result 1");
step1.put("actual", "Actual result 1");


List steps = new ArrayList();

Map data = new HashMap();
data.put("custom_steps_separated", steps);

For fields of type multi-select, TestRail expects an array of IDs (the IDs are configured as part of the custom field options):

List tags = new ArrayList();
tags.add(new Integer(1)); // Custom field value with ID 1
tags.add(new Integer(2)); // ID 2
tags.add(new Integer(5)); // ID 5

Map data = new 
data.put("custom_tags", tags);

I hope this helps!



awesome - the transform to java was what I was missing.

Regarding the multi-select ids. In case I have only the actual value and need to find out which id it corresponds to, I guess I can do this via a call to get_case_fields and them find my string there to get the actual id, right ?


Hello Andreas,

Great to hear that this helps :slight_smile:

Yes, you can use get_case_fields (or get_result_fields if it’s a result field field instead). This will return the custom field definitions including the names and IDs of the field values.