arthur-shaw / susoapi

R interface for Survey Solutions' APIs
https://arthur-shaw.github.io/susoapi/
Other
9 stars 5 forks source link

Update `get_questionnaires` because underlying endpoint deprecated in SuSo version 21.05 #4

Closed arthur-shaw closed 3 years ago

arthur-shaw commented 3 years ago

In #2 , @ashwinikalantri points out that:

get_questionnaire will only show questionnaires from the primary workspace. There is no way to set another workspace.

The issue is twofold:

  1. The underlying SuSo endpoint, GET ​/api​/v1​/questionnaires, may have been soft deprecated
  2. The REST endpoint above is not "scoped" to a workspace, and instead returns questionnaires in the primary workspace.

The solution is to rewrite the function to rely on the GraphQL endpoint and specify a target workspace in the query. For example:

{
  questionnaires(workspace: "workspace2target") {
    nodes {
      variable
      questionnaireId
      version
      id
      title
      defaultLanguageName
      translations {
        id
        name
      }
    }
  }
}

This may point to a larger set of function rewrites, since other objects are specific to workspaces (e.g., interviews, assignments, etc.) and, in principal, face the same problem, even if their endpoints have not yet been deprecated in 21.05.

Awaiting reply from SuSo dev team to decide on the optimal path--likely to be moving from REST to GraphQL endpoints for function business logic, and adding a workspace parameter to functions.

radyakin commented 3 years ago

While the REST endpoint has been deprecated, it still continues to work (as of v21.05.3) and allows extraction of lists of questionnaires from any workspace that the API user has access to;

. .suso.workspace="primary"

. .suso.qx_list

. list qx_identity

     +------------------------------------+
     |                        qx_identity |
     |------------------------------------|
  1. | 0434573c67b34d93b1f0799fb042f9e6$1 |
  2. | cdbc65c276664111a44bb602553ae727$1 |
  3. | f2b783f5aa1d41489bddc8aaf24f2947$1 |
  4. | ad59e88ffe7648f0881131b9ed57952e$1 |
  5. | a6e20ab2c7d34e5e9171f8c7ebfd7788$1 |
     |------------------------------------|
  6. | 03478235291748c3beddaa7fd70e53c6$1 |
     +------------------------------------+

. 
. .suso.workspace="chile1"

. .suso.qx_list

. list qx_identity

     +------------------------------------+
     |                        qx_identity |
     |------------------------------------|
  1. | ab814e96e64c4200b1657c2446d500ac$1 |
     +------------------------------------+

One can see the lists of the questionnaires are non-overlapping. Questionnaires from the "primary" workspace are not listed in the "chile1" workspace.