-
Notifications
You must be signed in to change notification settings - Fork 0
Update with intake forms #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mreigen
wants to merge
8
commits into
master
Choose a base branch
from
update-with-intake-forms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0dd635b
reads token and api endpoint urls from a shared source
26d3431
separate api version for future easy update
8a50f68
get intake form api ep
38652a6
update create-intake-form-repsonse
9582c35
add script to run create intake form response
d604412
Update create-intake-form-response.js
85068b2
Add documentation for intake forms, example of every field type
summasmiff c655313
remove console command
summasmiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const API_VERSION = "v1"; | ||
| const BASE_URL = "https://api.vendorful.com"; | ||
|
|
||
| export const TOKEN_ENDPOINT = `${BASE_URL}/auth/${API_VERSION}/token`; | ||
| export const VENDORS_API = `${BASE_URL}/vendors/${API_VERSION}`; | ||
| export const INTAKE_FORMS_API = `${BASE_URL}/intake-forms/${API_VERSION}`; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import fetch from "node-fetch"; | ||
| import { TOKEN_ENDPOINT } from "./../api_urls.js"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the primary purpose of this code is to serve as a document to communicate how to call the API, I think overt code is preferable, even if duplicative. |
||
|
|
||
| /* | ||
| * Creating a token with grant_type client_credentials can be | ||
|
|
@@ -15,8 +16,6 @@ import fetch from "node-fetch"; | |
| * contacting vendorful support. | ||
| */ | ||
|
|
||
| const TOKEN_ENDPOINT = "https://api.vendorful.com/auth/v1/token"; | ||
|
|
||
| async function createToken(id, secret, username) { | ||
| const params = { | ||
| grant_type: "client_credentials", | ||
|
|
@@ -38,7 +37,9 @@ async function main() { | |
| const email = process.argv[4]; | ||
| if (!secret) { | ||
| console.log("Please pass client_id and client_secret."); | ||
| console.log("> yarn run create-token-with-client-credentials <client_id> <client_secret> <optional_user_email>"); | ||
| console.log( | ||
| "> yarn run create-token-with-client-credentials <client_id> <client_secret> <optional_user_email>" | ||
| ); | ||
| } else { | ||
| try { | ||
| const token = await createToken(id, secret, email); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import fetch from "node-fetch"; | ||
| import { readFile } from "fs/promises"; | ||
| import { TOKEN_ENDPOINT, INTAKE_FORMS_API } from "./../api_urls.js"; | ||
|
|
||
| // Gets the token by posting secrets.json to the token endpoint. | ||
| // See secrets-sample.json for an example. | ||
| async function getToken() { | ||
| const response = await fetch(TOKEN_ENDPOINT, { | ||
| method: "post", | ||
| body: await readFile("secrets.json"), | ||
| headers: { "content-type": "application/json" }, | ||
| }); | ||
| return await response.json(); | ||
| } | ||
|
|
||
| async function createIntakeFormResponse( | ||
| { access_token }, | ||
| organizationId, | ||
| formId, | ||
| fields | ||
| ) { | ||
| const url = `${INTAKE_FORMS_API}/${organizationId}/intake-forms/${formId}`; | ||
| const response = await fetch(url, { | ||
| method: "post", | ||
| body: JSON.stringify({ fields }), | ||
| headers: { | ||
| authorization: `bearer ${access_token}`, | ||
| "content-type": "application/json", | ||
| }, | ||
| }); | ||
|
|
||
| return await response.json(); | ||
| } | ||
|
|
||
| // Example of fields from /GET response with "value" added | ||
| // Please see and run get-intake-forms.js to retrieve these field ids | ||
| // from the http response's body. | ||
| const fields = [ | ||
| { | ||
| body: null, | ||
| id: "874d5c18-c806-4688-babc-28b50b457bda", | ||
| multi: null, | ||
| name: "Short Text Test", | ||
| options: [], | ||
| required: false, | ||
| type: "string", | ||
| value: "test", | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "649e1fc1-1950-415d-b97e-a89f3e865969", | ||
| multi: null, | ||
| name: "Expanded Text Test", | ||
| options: [], | ||
| required: false, | ||
| type: "textarea", | ||
| value: "test", | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "d5d79f93-9c6f-4960-b5d0-e9bc5fa6a176", | ||
| multi: null, | ||
| name: "Checkbox UI Test", | ||
| options: [], | ||
| required: false, | ||
| type: "checkbox", | ||
| value: true, | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "d72fb676-6488-4404-9d89-1cd863031ec5", | ||
| multi: null, | ||
| name: "Single Select Test: Sandwich Choice", | ||
| options: ["Ham", "Roast Beef", "Pimento Cheese"], | ||
| required: false, | ||
| type: "select", | ||
| value: "Roast Beef", | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "7d0a3375-3642-44be-9b9b-a9f6b6da26b3", | ||
| multi: true, | ||
| name: "Multi-Select Test: Cookie Options", | ||
| options: ["Snickerdoodle", "Chocolate Chip", "Peanut Butter"], | ||
| required: false, | ||
| type: "select", | ||
| value: ["Snickerdoodle", "Chocolate Chip"], | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "4b7ebdff-afb3-484a-96e7-c7adb5ddab8a", | ||
| multi: null, | ||
| name: "Number Test", | ||
| options: [], | ||
| required: false, | ||
| type: "number", | ||
| value: 5, | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "7b9be557-5299-447c-8b5f-07214c3ea183", | ||
| multi: null, | ||
| name: "Range Test", | ||
| options: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], | ||
| required: false, | ||
| type: "range", | ||
| value: "4", | ||
| }, | ||
| { | ||
| body: null, | ||
| id: "f8b048f2-ab5d-4391-84b5-2c7b0a077552", | ||
| multi: null, | ||
| name: "Date Time Test", | ||
| options: [], | ||
| required: false, | ||
| type: "datetime", | ||
| value: new Date(), | ||
| }, | ||
| ]; | ||
|
|
||
| async function main() { | ||
| const token = await getToken(); | ||
| const organizationId = process.argv[2]; | ||
| const formId = process.argv[3]; | ||
| if (!formId || !organizationId) { | ||
| console.log("Please pass organizationId and formId."); | ||
| console.log("> yarn run get-intake-form <organizationId> <formId>"); | ||
| } else { | ||
| try { | ||
| const result = await createIntakeFormResponse( | ||
| token, | ||
| organizationId, | ||
| formId, | ||
| fields | ||
| ); | ||
| console.log(JSON.stringify(result, null, 2)); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import fetch from "node-fetch"; | ||
| import { readFile } from "fs/promises"; | ||
| import { TOKEN_ENDPOINT, INTAKE_FORMS_API } from "./../api_urls.js"; | ||
|
|
||
| // Gets the token by posting secrets.json to the token endpoint. | ||
| // See secrets-sample.json for an example. | ||
| async function getToken() { | ||
| const response = await fetch(TOKEN_ENDPOINT, { | ||
| method: "post", | ||
| body: await readFile("secrets.json"), | ||
| headers: { "content-type": "application/json" }, | ||
| }); | ||
| return await response.json(); | ||
| } | ||
|
|
||
| async function getIntakeForm({ access_token }, organizationId, formId) { | ||
| const url = `${INTAKE_FORMS_API}/${organizationId}/intake-forms/${formId}`; | ||
| const response = await fetch(url, { | ||
| method: "get", | ||
| headers: { | ||
| authorization: `bearer ${access_token}`, | ||
| "content-type": "application/json", | ||
| }, | ||
| }); | ||
|
|
||
| return await response.json(); | ||
| } | ||
|
|
||
| async function main() { | ||
| const token = await getToken(); | ||
| const organizationId = process.argv[2]; | ||
| const formId = process.argv[3]; | ||
| if (!formId || !organizationId) { | ||
| console.log("Please pass organizationId and formId."); | ||
| console.log("> yarn run get-intake-form <organizationId> <formId>"); | ||
| } else { | ||
| try { | ||
| const result = await getIntakeForm(token, organizationId, formId); | ||
| console.log(JSON.stringify(result, null, 2)); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API versioning is per-module, so it will make more sense, I think, to include it as part of the opaque string that makes up the base url. It is very likely that the version numbers will increment differently for each API. The Auth API will likely never increment, but if we introduce a breaking change in the Vendor API, we would not need to increment all API versions nor deprecate URLs for other modules.
The
TOKEN_ENDPOINTitself is a special case, as that is the name given in the OAuth2 specs, in that it is an opaque value to callers of the API that hopefully they would just paste into their OAuth2 client libraries that manage token expiration and renewal for them.