Professional Documents
Culture Documents
S.Radyakin
sradyakin@worldbank.org
April 8, 2021
Contents
1 Survey Solutions API Client for Stata 3
1.1 Create a new API client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Questionnaires 5
2.1 Get a list of questionnaires on the server . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Get a list of interviews of a questionnaire on the server . . . . . . . . . . . . . . . . 5
2.3 Get a questionnaire document in JSON format . . . . . . . . . . . . . . . . . . . . . 6
2.4 Set audio audit for the survey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Get status of audio audit for the survey . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Assignments 8
3.1 Get details of an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Assign an assignment to a new responsible . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Archive an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Unarchive an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 Close an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 Change quantity for an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.7 Get quantity setting for an assignment . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.8 Get audio audit status for an assignment . . . . . . . . . . . . . . . . . . . . . . . . 10
3.9 Set audio audit status for an assignment . . . . . . . . . . . . . . . . . . . . . . . . 11
3.10 Get assignment’s history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.11 Create an assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Interviews 14
4.1 Approve an interview by a supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2 Reject an interview by a supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.3 Unapprove an interview by a headquarters user . . . . . . . . . . . . . . . . . . . . 15
4.4 Approve an interview by a headquarters user . . . . . . . . . . . . . . . . . . . . . . 15
4.5 Reject an interview by a headquarters user . . . . . . . . . . . . . . . . . . . . . . . 15
4.6 Get a PDF document for the interview . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.7 Get statistics for the interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.8 Get history of the interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.9 Get answers of the interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.10 Delete an interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.11 Assign an interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.12 Assign supervisor/team to an interview . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.13 Add a comment to a question in the interview by question GUID . . . . . . . . . . 18
4.14 Add a comment to a question in the interview by variable name . . . . . . . . . . . 18
5 Data export 20
5.1 Download data export file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6 Maps 22
6.1 Get list of maps and maps-to-user assignments . . . . . . . . . . . . . . . . . . . . . 22
6.2 Add an assignment of a map to a user. . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.3 Delete an assignment of a map from a user. . . . . . . . . . . . . . . . . . . . . . . 23
1
6.4 Delete a map from the server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
9 Calendar events 30
9.1 Add or update a calendar event to an interview . . . . . . . . . . . . . . . . . . . . 30
9.2 Delete a calendar event to an interview . . . . . . . . . . . . . . . . . . . . . . . . . 30
10 Workspaces 32
10.1 Obtain list of workspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
10.2 Get details of a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
10.3 *Create a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
10.4 *Delete a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
10.5 *Obtain workspace status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
10.6 *Disable a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
10.7 *Enable a workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
10.8 *Assign users to workspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
10.9 Update a workspace title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
11 Photo credits 37
13 Glossary 39
2
1 Survey Solutions API Client for Stata
Survey Solutions API client for Stata is a software that facilitates the control of a Survey
Solutions data server from Stata scripts.
Requirements:
• Stata 16.0 or newer.
• Python 3.8 or newer (installed and accessible from Stata).
Where to get:
3
• Stata: https://www.stata.com
• Python: https://www.python.org/downloads/
• This API client: in Stata command prompt type ssc install susoapi
python : import s y s ; p r i n t ( s y s . v e r s i o n )
If you are getting an error, then your Python installation is unusable from Stata. Refer to the
Stata manual/support on how to install and configure Python for integration with Stata.
Parameters
• username - name of the API user account, for example, "WeeklyAPI "
4
2 Questionnaires
Options
• frame - (optional) frame name where to save the list. If not specified, the current frame is
cleared and used to store the list.
5
Options
• frame - (optional) name of the frame to save the list of the interviews.
Options
• qversion - version of the questionnaire as imported to the HQ, numeric, for example: 2
Parameters
• qversion - version of the questionnaire as imported to the HQ, numeric, for example: 2
6
2.5 Get status of audio audit for the survey
. qx_getaudio qguid qversion
Parameters
• qversion - version of the questionnaire as imported to the HQ, numeric, for example: 2
Saved results
• r(record_audio) - numeric 1=ON or 0=OFF.
• r(status_code) - numeric status code for API query. Successful completion is indicated by
code 200.
7
3 Assignments
Parameters
Errors
Parameters
8
Errors
Parameters
Errors
Parameters
Errors
Parameters
Errors
9
3.6 Change quantity for an assignment
. assignments _c ha ng e qu an ti t y assignmentid number
Parameters
• assignmentid - numeric identifier of the assignment, for example: 1007.
Errors
• Error 5001 is returned if the assignmentid is not specified.
Parameters
• assignmentid - numeric identifier of the assignment, for example: 1007.
Saved results
• r(can_change_quantity) - numeric 1=quantity can be changed or 0=quantity cannot be
changed.
• r(status_code) - numeric status code for API query. Successful completion is indicated by
code 200.
Errors
• Error 5001 is returned if the assignmentid is not specified.
Parameters
• assignmentid - numeric identifier of the assignment, for example: 1007.
Saved results
• r(record_audio) - numeric 1=ON or 0=OFF.
10
• r(status_code) - numeric status code for API query. Successful completion is indicated by
code 200.
Errors
• Error 5001 is returned if the assignmentid is not specified.
Parameters
• assignmentid - numeric identifier of the assignment, for example: 1007.
• value - numeric value for the audio audit status of the assignment (0=OFF, any other
value=ON), for example: 1.
Saved results
• r(record_audio) - numeric 1=ON or 0=OFF.
• r(status_code) - numeric status code for API query. Successful completion is indicated by
code 200.
Errors
• Error 5001 is returned if the assignmentid is not specified.
Parameters
• assignmentid - numeric identifier of the assignment, for example: 1007.
• framename - (optional) frame name where to save the assignment history, for example: "his-
tory". If not specified, the history is saved to the current frame.
Errors
11
• Error 5001 is returned if the assignmentid is not specified.
• Error -10404 is returned if the assignment with assignmentid is not found on the server.
Options
• responsible - account name of a person designated responsible for the assignment, for ex-
ample: SergiyInt. NB: for web interviews the responsible must be a user in the interviewer
role.
• qxversion() - (optional) numeric version of the questionnaire (as assigned when the ques-
tionnaire is imported to the HQ), for example: 2. When the option is not specified version 1
is implied.
• quantity() - (optional) quantity of interviews requested in this assignment, for example: 12.
When the option is not specified, quantity 1 is implied.
• email() - (optional) respondent’s email for sending the invitations and reminders for a web
interview.
• webmode() - (optional) whether the assignment should be created in web mode. Specify 1 for
web mode assignments, and 0 for regular assignments. If the option is not specified, regular
assignments will be created.
• audio() - (optional) whether audio audit should be collected for this assignment (1=on,
0=off). If the option is not specified, the audio audit will not be collected.
Errors
12
• Error 7001 is returned if the password option is specified, but the assignment is created not
in web mode (option webmode is 0).
• Error 7002 is returned if the email option is specified, but the assignment is created not in
web mode (option webmode is 0).
• Error 7003 is returned if the quantity option is more than 1, but the assignment is created
not in web mode (option webmode is 0).
13
4 Interviews
Parameters
Parameters
• responsibleguid - (optional) GUID identifier of the new person responsible for the rejected
interview.
14
4.3 Unapprove an interview by a headquarters user
. interviews_unapprove guid [ comment ]
Parameters
Parameters
Parameters
• responsibleguid - (optional) GUID identifier of the new person responsible for the rejected
interview.
Parameters
• saveto - name of the file where the PDF document for this interview must be saved.
15
4.7 Get statistics for the interview
. interviews_getstats guid
Parameters
• guid - GUID identifier of the interview.
Saved results
• r(InterviewId) - GUID of the interview, for example: "81784070-1e55-457c-b32e-b52d9672d9c4";
• r(InterviewKey) - interview key, for example: "12-34-56-78";
• r(Status) - status of the interview, for example: "Completed";
• r(ResponsibleId) - GUID of the responsible person, for example: "39ad7fa7-4215-468b-9861-
9a68b20662c2"
• r(ResponsibleName) - login name of the current responsible, for example: "SergiyHQ";
• r(InterviewDuration) - duration of the interview, for example: "00:14:48.3716360"
• r(UpdatedAtUtc) - date and time of the last update to the interview data, for example:
"2021-03-19T13:00:40.048662Z";
• r(AssignmentId) - numeric assignment ID from which this interview has been started, for
example: 30711 ;
• r(NumberRejectionsByHq) - number of rejections by HQ user(s), for example: 0.
• r(NumberRejectionsBySupervisor) - number of rejections by supervisor user(s), for example:
2.
• r(NumberOfInterviewers) - number of interviewers that this interview was processed by, for
example: 1.
• r(ForSupervisor) - number of supervisor questions, for example: 3.
• r(ForInterviewer) - number of questions for interviewer, for example: 100.
• r(WithComments) - number of questions with comments, for example: 4.
• r(Invalid) - number of questions with errors, for example: 1.
• r(Valid) - number of questions without errors, for example: 99.
• r(Flagged) - number of questions with flags, for example: 0.
• r(NotFlagged) - number of questions without flags, for example: 100.
• r(Answered) - number of questions which have been answered, for example: 93.
• r(NotAnswered) - number of questions which have not been answered, for example: 7.
Parameters
• guid - GUID identifier of the interview.
• framename - (optional) name of the frame where the history of the interview must be saved.
If not specified, the current frame is used.
Interview history frame data structure
16
string* timestamp (for example, "2021-03-19T13:00:13.263127Z ")
string* offset (for example, "-04:00:00 ")
string* action (for example, "Created ")
string* originator_name (for example, "MariaHQ")
string* originator_role (for example, "Interviewer ")
string* parameters (for example, "{’question’: ’OPZ401Q’, ’answer’: ’750000’, ’roster’:
’1,3’}")
*NB: The exact storage types of the string variables depend on the content length and may vary.
Parameters
• framename - (optional) name of the frame where the answers of the interview must be saved.
If not specified, the current frame is used.
Parameters
Errors
• Error 10102 is returned if the interview with ID guid may not be deleted.
17
4.11 Assign an interview
. interviews_assign intguid responsibleguid
Parameters
Parameters
Options
• questionguid() - GUID identifier of the question where the comment must be added. NB: if
GUID of the question is not known, see next section 4.14 for the equivalent method utilizing
the variable name instead.
• comment() - text of the comment that must be added, for example: comment("Strange value")
• rostervector() - rostervector address of the item if the question is part of the roster, for ex-
ample: rostervector(5). NB: rostervector() (if specified) is expected to be formatted according
to the Survey Solutions rules: specifically as #, or #-#, or #-#-#, or #-#-#-#.
Options
18
• varname() - variable name of the question where the comment must be added. NB: if varname
of the question is not known, see previous section 4.13 for the equivalent method utilizing the
question GUID instead.
• comment() - text of the comment that must be added, for example: comment("Strange value")
• rostervector() - rostervector address of the item if the question is part of the roster, for ex-
ample: rostervector(5). NB: rostervector() (if specified) is expected to be formatted according
to the Survey Solutions rules: specifically as #, or #-#, or #-#-#, or #-#-#-#.
19
5 Data export
Options
• saveto - name of the file to save the exported date, for example: "C:/data/export.zip".
20
specified, the meta-information about the questionnaire (JSON-document, PDF-documents,
etc) is excluded.
• status - (optional) filter by interview status. If specified, exported interviews data will be
restricted to the data from interviews in that status, otherwise by default the data from all
interviews is exported.
• exporttype - (optional) type of data file requested for export, can be one of the data types
listed below. For example: "Paradata". If not specified, then "STATA"is assumed.
• from - (optional), if specified, restricts the export to interviews modified since the specified
date, for example: "2021-01-01T19:23:43.375Z ". NB: if option from() is specified, then option
to() must also be specified.
• to - (optional), if specified, restricts the export to interviews modified before the specified
date, for example: "2021-01-01T19:23:43.375Z ". NB: if option to() is specified, then option
from() must also be specified.
21
6 Maps
Parameters
• maps - frame name for placing the list of maps currently on the server
• users - (optional) frame name for placing the list of users-to-maps assignments.
22
double ymaxval
*NB: The exact storage types of the string variables depend on the content length and may vary.
Parameters
• map - name of the map from the list of maps currently on the server, for example, "ukraine.tif "
Parameters
• map - name of the map from the list of maps currently on the server, for example, "ukraine.tif "
Parameters
• map - name of the map from the list of maps currently on the server, for example, "ukraine.tif "
23
7 Server notice message
Parameters
• message - New message to be set up on the server as a notice message.
24
8 Users and user accounts
Saved results
As a result of execution of this method, the following properties of the API-client are updated:
• .userid - GUID of the user account.
• .userroles - roles that the account is having in the server, typically "APIUSER" for API user
accounts.
• .userworkspaces - list of workspaces that this account has access to.
Options
• role - role of the new account, can be one of "interviewer ", or "supervisor ", or "headquarters".
• username - user name of the new account (must be unique on the server).
25
• password - password for the new account, must satisfy the password security requirements
for the server.
• supervisor - name of the supervisor for the new account. Must be specified for the interviewer
accounts, may not be specified for any other accounts. Supervisor with this account must
already exist on the server.
Saved results
• r(UserID) - GUID of the newly created user account
Parameters
Saved results
• r(UserId) - account GUID as specified in the query
• r(UserName) - account name corresponding to the specified GUID
• r(Role) - account role in the system
• r(FullName) - full name of the user (if specified)
• r(Email) - contact email of the user (if specified)
• r(PhoneNumber) - contact phone number of the user (if specified)
• r(CreationDate) - date when the account was created
• r(isArchived) - (1=archived; 0=not archived)
• r(isLocked) - (1=locked; 0=not locked)
Parameters
Saved results
• r(UserName) - account name corresponding to the specified GUID
26
• r(FullName) - full name of the user (if specified)
• r(Email) - contact email of the user (if specified)
• r(PhoneNumber) - contact phone number of the user (if specified)
• r(CreationDate) - date when the account was created
• r(isArchived) - (1=archived; 0=not archived)
• r(isLocked) - (1=locked; 0=not locked)
Parameters
Saved results
• r(UserName) - account name corresponding to the specified GUID
• r(SupervisorName) - account name of the supervisor of this interviewer
• r(SupervisorId) - account GUID of the supervisor of this interviewer
• r(FullName) - full name of the interviewer (if specified)
• r(Email) - contact email of the interviwer (if specified)
• r(PhoneNumber) - contact phone number of the interviewer (if specified)
• r(CreationDate) - date when the account was created
• r(isArchived) - (1=archived; 0=not archived)
• r(isLocked) - (1=locked; 0=not locked)
• r(isLockedBySupervisor) - (1=locked; 0=not locked)
• r(isLockedByHeadquarters) - (1=locked; 0=not locked)
Parameters
• frame - (optional) frame name to save the list of supervisors. If not specified, the current
frame will be used.
27
8.7 Get the list of interviewer accounts in a team
. users_interviewers guid frame
Retrives the list of interviewer accounts in a team of a particular supervisor.
Parameters
• guid - GUID of the supervisor/team.
• frame - (optional) name of the frame to be created for the list of the interviewers.
Supervisors list frame data structure
strL user_name (for example, "Natalia")
str36 user_id (for example, "978d72ab-82b1-4c7b-a055-cf8922dde4e6")
str40 creation_date (for example, "2020-10-05T15:33:30.317233Z")
byte is_locked (1=locked, 0=not locked)
Parameters
• guid - GUID of the user account on the server to be archived.
Parameters
• guid - GUID of the user account on the server to be unarchived.
Options
• user - GUID of the interviewer account on the server, for which the detailed actions log is
requested. For example, user(b361cc01-da5d-432e-b926-799f73c7e198).
• framename - (optional) if specified, the detailed actions log will be placed in this new frame,
otherwise the log will be placed into the current frame.
• from - (optional), if specified restricts the detailed actions log to start from this date. Example:
from(2019-01-13T14:48:58Z). NB: if option from() is specified, then option to() must also be
specified.
28
• to - (optional), if specified restricts the detailed actions log to end on this date. Example:
to(2021-01-13T14:48:59Z). NB: if option to() is specified, then option from() must also be
specified.
29
9 Calendar events
Parameters
• interviewkey - Interview key for the interview, where the calendar event must be modified,
for example: "12-34-56-78 ".
• text - Text of the note of the calendar event, for example: "All household members will be
available for interviewing".
Parameters
30
• interviewkey - Interview key for the interview, where the calendar event must be deleted,
for example: "12-34-56-78 ".
31
10 Workspaces
Workspaces management is a privilege and responsibility. Only some of the methods listed below
are available to the API users. Other methods denoted with an asterisk (*) in the description are
available only to the Survey Solutions administrator. You can switch the account to be used for
API queries already after the initialization of the API client, if necessary:
Options
• frame() - (optional) name of the frame where the list of the workspaces must be saved, for
example: frame("wspaces").
• userguid() - (optional) GUID of the user, if specified the list will include only the workspaces,
to which this user is granted access to.
32
• includedisabled - (optional), if specified the list will also include disabled workspaces; if not
specified, then only enabled workspaces.
Parameters
Errors
Saved results
• r(Name) - specified name of the workspace.
• r(DisplayName) - display name that is attributed to this workspace.
• r(DisabledAtUtc) - blank for workspaces that are not disabled, for disabled workspaces times-
tamp indicating when the workspace was disabled.
Parameters
• title - title of the new workspace, for example: "Labour force survey 2021q4". The title is
optional. The name of the workspace will be used also as a title if the title is not specified.
Errors
33
10.4 *Delete a workspace
. workspaces_delete name , irreversible
Parameters
• name - name of the workspace to be deleted, for example: lfs.
• irreversible - literally the word irreversible. This option is not optional. The user must
understand that the command he issues may cause irreversible damage.
Errors
• Error 5001 is returned if the workspace name is not specified.
• Error 198 is returned if the option irreversible is not specified.
Parameters
• name - name of the workspace the status of which is to be examined, for example: lfs.
Errors
• Error 5001 is returned if the workspace name is not specified.
Saved results
• r(WorkspaceName) - specified name of the workspace, for Example: "census".
• r(WorkspaceDisplayName) - display name that is attributed to this workspace, for example:
"Population Census 2021".
• r(CanBeDeleted) - an flag indicating whether the workspace may be deleted (1) or not (0).
• r(ExistingQuestionnairesCount) - number of questionnaires that are imported to this workspace.
• r(InterviewersCount) - number of interviewer accounts in this workspace.
• r(SupervisorsCount) - number of supervisor accounts in this workspace.
• r(MapsCount) - number of maps in this workspace.
Parameters
• name - name of the workspace, for example: lfs.
Errors
• Error 5001 is returned if the workspace name is not specified.
34
10.7 *Enable a workspace
. workspaces_enable name
Parameters
• name - name of the workspace, for example: lfs.
Errors
• Error 5001 is returned if the workspace name is not specified.
• add - give the user(s) access to specified workspace(s) in addition to any other workspaces
she currently has access to.
• remove - take away the access permission to the specified workspace(s) leaving any other
access permissions unaffected.
• assign - replace current access permissions with the access only to specified workspaces.
Options
• users() - one or more user account names, for example: frame("SergiyInt"). Multiple account
names must be delimited with spaces, like so: frame("SergiyInt SandraSup").
• workspaces() - one or more names of the workspaces, for example: "agcensus". Multiple
workspace names must be delimited with spaces, like so: "census lfs pricesvy".
Errors
• Error 5001 is returned if the workspaces() is not specified.
Parameters
• name - name of the workspace, for example: lfs.
• title - new title of the workspace, for example: "Labour force survey 2021q4".
35
Errors
36
11 Photo credits
37
12 HTTP Status codes
Survey Solutions server returns HTTP status codes for the requests it receives. A comprehensive
reference on the HTTP status codes and their interpretation is available for example in Wikipedia.
Below is a short list of most commonly returned status codes for a quick reference.
2xx success:
200 OK
201 Created
202 Accepted
204 No Content
38
13 Glossary
Short definitions of objects from the Survey Solutions nomenclature are listed below.
39