jhpyle / docassemble

A free, open-source expert system for guided interviews and document assembly, based on Python, YAML, and Markdown.
https://docassemble.org
MIT License
796 stars 258 forks source link

POST /session question #275

Closed jshum closed 4 years ago

jshum commented 4 years ago

Hi, thank you for building docassemble. It's truly awesome. I'm trying to develop a simple doc generator for application form. I'd like to use the API to access the details of the interview and create submissions.

I'm having trouble with posting the variables to the question/session. I've looked through the docs and some other Github issues, but still having some trouble understanding what's going on.

Results from GET /question

{
  "allow_going_back": false,
  "browser_title": "Application",
  "display_section": null,
  "display_title": "Application",
  "event_list": [
    "Applicant_Name"
  ],
  "exit_label": "Exit",
  "exit_link": "exit",
  "exit_url": null,
  "fields": [
    {
      "active": true,
      "datatype": "text",
      "label": "Applicant Name",
      "number": 0,
      "required": true,
      "variable_name": "Applicant_Name"
    },
    {
      "active": true,
      "datatype": "text",
      "label": "Applicant Address",
      "number": 1,
      "required": true,
      "variable_name": "Applicant_Address"
    }
  ],
  "lang": "en",
  "language": "*",
  "message_log": [],
  "progress": 0,
  "questionName": "Question_0",
  "questionText": "Please fill in.",
  "questionType": "fields",
  "section": null,
  "sections": [],
  "short_title": "Application",
  "steps": 1,
  "title": "Application",
  "validation_messages": {}
}

JSON Body for POST /session

{
    "key": "xxx",
    "i": "yyy",
    "session": "xxx",
    "secret": "xxx",
    "variables": {
        "Applicant_Name": "123"
    },
    "question_name": "Question_0",
    "advance_progress_meter": 1
}

But I keep getting 400 Error with "Unable to obtain interview dictionary." as the error message. Any thoughts on why this is the case?

I'm not actually quite sure what the allowed content within variables for the POST /session call is. Can you only set variables which were returned in the /session call? If that's the case, how can you set question variables programmatically through the API?

Thank you, appreciate any answers or hints you may be able to provide

jshum commented 4 years ago

I also tried which seems to be the suggestion from this: https://github.com/jhpyle/docassemble/issues/141

{
    "key": "xxx",
    "i": "yyy",
    "session": "xxx",
    "secret": "xxx",
    "variables": {
        "url_args['Applicant_Name']": "John"
    },
    "question_name": "Question_0",
    "advance_progress_meter": 1
}
jhpyle commented 4 years ago

Everything looks fine based on what you have listed. The error you are getting means that when it searches the userdict table in the SQL database (which stores interview answers) using the i and session parameters you gave it, it found zero results. Maybe you are giving it the wrong i or the wrong session?

You can set any variable at any time with the API.

Setting the url_args through the API is not the way to go. I wouldn't pay too much attention to the GitHub issues history. Most Q&A activity is on Slack.

jshum commented 4 years ago

thank you @jhpyle .

ah I figured it out. I had spaces in my file name, and I had mistakenly copied over the url-encoded param that was in the GET request where it changes spaces to %20. Should have kept the version with the actual spaces.