Skip to content

Commit

Permalink
add raw response endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaslavskiy committed Apr 16, 2024
1 parent bbf0f9f commit a82678b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion qualtrix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SurveyModel(BaseModel):

class ResponseModel(SurveyModel):
responseId: str
raw: bool | None = False


class SessionModel(SurveyModel):
Expand Down Expand Up @@ -52,7 +53,7 @@ async def get_bulk_responses(request: SurveyModel):
@router.post("/response")
async def get_response(request: ResponseModel):
try:
return client.get_response(request.surveyId, request.responseId)
return client.get_response(request.surveyId, request.responseId, request.raw)
except error.QualtricsError as e:
raise HTTPException(status_code=400, detail=e.args)

Expand Down Expand Up @@ -171,6 +172,11 @@ async def session(request: SessionModel):
raise HTTPException(status_code=400, detail=e.args)


@router.get("/contact/{contactId}")
async def contact(contactId: str):
return client.get_contact_by_id(contactId)


@router.get("/contact/{contactId}/responseIds")
async def dist(contactId: str):
return client.get_responseIds_by_contact(contactId)
Expand Down
5 changes: 4 additions & 1 deletion qualtrix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def get_link(target_survey_id: str, distribution_id: str):
return link


def get_response(survey_id: str, response_id: str):
def get_response(survey_id: str, response_id: str, raw: bool):
for i in range(settings.RETRY_ATTEMPTS):
r = requests.get(
settings.BASE_URL + f"/surveys/{survey_id}/responses/{response_id}",
Expand Down Expand Up @@ -466,6 +466,9 @@ def get_response(survey_id: str, response_id: str):

survey_answers["response"] = answer

if raw:
survey_answers["raw"] = response

return survey_answers


Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi==0.109.2
uvicorn==0.27.0.post1
fastapi==0.110.1
uvicorn==0.29.0
starlette-prometheus==0.9.0
google-api-python-client==2.116.0
google-auth-httplib2==0.2.0
Expand Down

0 comments on commit a82678b

Please sign in to comment.