How can I create an asignment for non cover variables through API?

I don’t have any problem to preload information from the cover section through the API, but I would like to pre-load sex and age of the household members. I am attaching an example of my questionnaire structure.

Hello @klehmann ,

I have never seen anyone separating sex and age of persons into separate rosters. What is the reason for doing this?

When you create assignments through API pass the person’s rowcode in the roster as a suffix of the question’s identity. Clearly it’s not possible to say exactly without having the identities of the questions of your questionnaire, but here is an example of the JSON to populate the household (located in area 51, address FOO, and another hh-level question BAR) with three persons, first of which is known to be Sergiy, a 69 y.o. male, others unknown:

{
"Responsible": "SergiyInt",
"Quantity": 1,
"QuestionnaireId": "caa7213a-bdc1-448b-b360-b983d17459d6$3",
"IdentifyingData": [
{
"Identity": "5a94f13d32fed17f33929d6f1e30ac75",
"Answer": "FOO"
},
{
"Identity": "ab7274795788a8bb86efb65ac4e3fcb0",
"Answer": "51"
},
{
"Identity":"c81fd2b087626ef13daf623581ea33d8",
"Answer": "BAR"
},
{
"Identity":"d3c09d79a8a213547e46ff1d6b8b7510",
"Answer": "3"
},
{
"Identity":"d510ee3c33f1a52189bb4a9c7699c45d_0",
"Answer": "SERGIY"
},
{
"Identity":"64238a390f029df36b899743bf5d4207_0",
"Answer": "69"
},
{
"Identity":"5d920df4f22a9f52f755055610e65ce6_0",
"Answer": "1"
}
]
}

Hope this helps.
Best, Sergiy

Hi @sergiy

Thank you for your answer. In the json file I can see a parameter called PublicKey. Is this the question id? In my example the PublicKey for name question is 4870112a-a80a-41db-99e9-d7d7afb142a4. Should I use the identity 4870112aa80a41db99e9d7d7afb142a4_0 for the name Sergiy?

Regarding your question, the reason is we believe it is easier for the interviewer ask for the sex information of all household members at the same time and then ask for the age.

Strange.
If that is the case then a YN-multiselect question will probably be a much more compact way of asking.

Who are females in this household??? 
(Y for female, N for male)
 - John
 - Mary
 - Peter
 - Maryna
 - Natalia

Although, keep in mind that since this becomes a linked question - it can’t be preloaded!

Yes, please try it out.

Sergiy,

I am using the following json file, but the API is returning error 500.

A variable name may not start with a digit:

There were no variable names in my example code, please retry without them.

Details of server errors are recorded in server logs.

@sergiy, how should one think about the rowcode component of Identity? For list-triggered rosters, are indices zero-based (even though 1-based for preloading in the GUI)? For all rosters, should the indices be the same as they would be when preloading in the GUI?

Dear @sergiy,

Unfortunately I still can’t load roster data :frowning: . I tried out with your example, but I don’t know what is happening.

I have been thinking and maybe the problem is that I have a roster with a list question as source. Should I load the list of members before the sex and age data? Unlike your example, I don’t have the number of household members and I don’t know if the API is creating automatically the number of rows for my roster. If that is the case, how can I preload list questions?

Sorry for all the inconvenience.

Yes. If you are preloading rosters, you must set the roster trigger question accordingly in the same API query:

{
  "Responsible": "SergiyIntNov",
  "Quantity": 1,
  "QuestionnaireId": "51184c44-9920-47c6-ab0e-7d1c7cf6fdd8$2",
  "IdentifyingData": [
    {
      "Identity": "5589be33d8036d6913c1a3b12f644f8b",
      "Answer": "['JOHN','MARY','PETER']"
    }
  ],
}

Thanks @sergiy!! Now is working :grinning_face_with_smiling_eyes:

Thank you for confirming!
Best, Sergiy