Access
Note: API calls return JSON formatted data.
Click here for Drupal reference
=== Authentication ===
* Note: you can log in with a browser instead of the curl example below, simply by accessing the survey and logging in with an account that has administrative access.
* To logout, use this URL: https://adventisthealthstudy.org/user/logout
* To logout of the test site, use this: https://s9-adventisthealthstudy.lluh.org/user/logout
* Curl is used as an example here, but any software capable of get/post calls will work.
Login command (supply the appropriate username and password):
curl \
--header "Content-type: application/json" \
-c cookie.txt \
--request POST "https://s9-adventisthealthstudy.lluh.org/user/login?_format=json" \
--data '{"name":"admin", "pass":"admin"}'
If login is successful it will save a cookie.txt file in the folder you ran that command.
=== What's next? ===
After logging in, you can access any available APIs, such as accessing a user account:
curl \
--header "Content-type: application/json" \
-b cookie.txt \
--request GET "https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[uid][value]=1521"
Or the survey API entry point:
curl \
--header "Content-type: application/json" \
-b cookie.txt \
--request GET "https://s9-adventisthealthstudy.lluh.org/api/surveys?_format=json&in_draft=1"
=== API endpoints ===
Key fields
* webform_id: the name of the webform (aka sub-survey, e.g. "sandwiches").
* serial: auto ID per form.
* sid: survey user ID (unique).
* uuid: user unique ID (unique).
* uid: is a way of identifying each record. It contains: target_id, target_type, target_uuid, url.
Retrieve a list of users
https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?fields[user--user]=drupal_internal__uid,field_first_name,field_last_name,mail,field_last_survey&filter[field_has_completed_profile][value]=1
Note that fields can be added or removed from this getter as needed. Also, the entire fields parameter can be omitted to return all available fields, such as:
https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[field_has_completed_profile][value]=1
Other fields can also be used, such as first name.
https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[field_first_name][value]=michael
Other operations are possible to do more flexible data calls. See the drupal json api documentation for more details.
[[https:s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[field_first_name][value]=mich&filter[field_first_name][operator]=CONTAINS|Example:]]<code>https:s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[field_first_name][value]=mich&filter[field_first_name][operator]=CONTAINS
Retrieve a list of all webforms
https://s9-adventisthealthstudy.lluh.org/jsonapi/webform/webform?fields[webform--webform]=drupal_internal__id
* id: ab082ee3-192b-4506-9f7e-2bca8760f56b, drupal_internal_id: additions
* id: 06a38bb3-5ebc-41e4-b709-9cc244906630, drupal_internal_id: asian_food
* id: ddc98ca5-b1fd-43dc-aab0-ffb1503cbc01, drupal_internal_id: base_ahs_form
* id: 8a8298d8-f915-4afc-a19b-51554ea578ed, drupal_internal_id: beverages_juices
* id: 72009bd7-f300-4ed5-a197-7e8e5120e4f6, drupal_internal_id: breads_grains
* id: 5b852898-ea19-493b-ba24-f88c85373eed, drupal_internal_id: casseroles,_hotdishes,_loaves
* id: 76596ade-daf8-488b-b135-7e3da36aabde, drupal_internal_id: census_data
* id: 4bc0ae5e-f5b6-474b-9aa2-231363b314d6, drupal_internal_id: cereal
* id: 9c563296-edd7-44ad-bd92-001d6174b797, drupal_internal_id: chili
* id: 2319bdd2-05bc-412c-839e-3ae1f297936f, drupal_internal_id: contact_us
* id: 20829baf-a92c-4e2d-8400-e54cc9316ac1, drupal_internal_id: cooked_mixed_vegetables
* id: 07fb6b10-c0ba-4d86-a706-04a17dc79068, drupal_internal_id: dairy_alternatives
* id: 5e4cba9b-4750-4b66-999f-8e0f5424f3c7, drupal_internal_id: eating_habits
* id: 340512e7-28c1-4ad5-ac97-8e02136432e5, drupal_internal_id: egg_based_dishes
* id: a01646c5-d2c4-45d1-bb8c-7091cab16c99, drupal_internal_id: female_history
* id: f6e34f2e-3b11-4761-a322-0ac3acd07b17, drupal_internal_id: fruits
* id: 33ad58af-53c2-4cdf-8909-59c14e6f133b, drupal_internal_id: legumes
* id: d57d66ac-3115-44bd-b538-2a5ac593036c, drupal_internal_id: lifestyle_habits
* id: 193b5405-dd6d-4f27-b05e-52fb13397e1d, drupal_internal_id: meat_alternatives
* id: 49c5f0b2-2657-4aa6-b668-5b8547b03721, drupal_internal_id: meats_fish
* id: 308a0aa3-ae12-4eb4-9cc9-0c75905c1507, drupal_internal_id: medical_history
* id: 1d97f86a-3788-4db4-aba8-19515c632e6e, drupal_internal_id: mexican_style_dishes
* id: d65a2496-10f4-4917-987e-15d7ac5a4346, drupal_internal_id: mixed_foods
* id: f5b7f1db-4d2b-4287-b98c-bfbe3f83459f, drupal_internal_id: newsletter_subscription
* id: 6e62417a-2b26-4663-80d8-b3380760b4e7, drupal_internal_id: noodles_rice
* id: 9b5c515f-457a-472c-85fd-73800eff8ac2, drupal_internal_id: nuts_seeds
* id: 695ba2bc-c240-4b40-80cd-9be153fd6179, drupal_internal_id: pasta_rice
* id: c877c3ab-69aa-4a64-835e-8f1628a7ec1c, drupal_internal_id: pizza
* id: 2e4b0dce-6af2-4442-8d16-644e39724b7b, drupal_internal_id: sandwiches
* id: 80cb5e70-a659-432f-a685-287166cd5194, drupal_internal_id: smoothies
* id: c1b665e4-5479-4bc2-8ee2-a70682343564, drupal_internal_id: snacks
* id: fb39ff2e-c65c-4cc6-88d5-6791401f77af, drupal_internal_id: soups
* id: e7250754-eba4-4646-818c-26482da47614, drupal_internal_id: stews
* id: cef33151-0f94-4a02-abed-76509825db63, drupal_internal_id: supplements
* id: c13348e0-ea9d-44ff-b520-1a79e6b3d54d, drupal_internal_id: vegetable_dishes
* id: d509210b-4edf-44d6-9193-3cc414ca0c9d, drupal_internal_id: vegetables
Access list of submissions (filterable & pageable -- unsure if sortable)
https://s9-adventisthealthstudy.lluh.org/api/surveys?_format=json&in_draft=1
* in_draft=1 or in_draft=0 (true or false)
* completed=2021-01-01 (entries completed after date)
* changed=YYYY-MM-DD (entries changed after date)
* completed and changed are optional
* page=0 (0 based page)
Note: even though each sub-survey is completed independently of others, they do not get marked "completed" (in_draft=0) until the entire survey is complete. This is because they have to be left open for edits.
Access details of a submission section
Format: /webform_rest/[webform_id]/submission/[uuid]
Example for sandwiches, uuid c2b13bf1-be3b-4f38-b547-97ecc7874887:
https://s9-adventisthealthstudy.lluh.org/webform_rest/sandwiches/submission/c2b13bf1-be3b-4f38-b547-97ecc7874887?_format=json
You can access a user profile using one of their ID's.
Access user profile via UUID:
https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[id]=c9cee1a4-4806-46ea-806c-d508acfdd55d
Access user profile via UID:
https://s9-adventisthealthstudy.lluh.org/jsonapi/user/user?filter[uid][value]=1521
More advanced filtering methods
See Drupal JSON module filtering documentation:
#Query the subject's uid and webform name:
https://s9-adventisthealthstudy.lluh.org/api/surveys?_format=json&uid=1521&webform_id=supplements
#Use the SID to call up the submission details:
https://s9-adventisthealthstudy.lluh.org/admin/structure/webform/manage/supplements/submission/406
#More specifically, remove the administrative note on the "notes" page:
https://s9-adventisthealthstudy.lluh.org/admin/structure/webform/manage/supplements/submission/406/notes