Skip to content

Commit 857947b

Browse files
brandoncharneskybrandoncharnesky
andauthored
Update query parameters and add documentation (#11)
* Update queryParams in getFromAPI * Extra notes for environment setup --------- Co-authored-by: brandoncharnesky <BrandonCharnesky@careeevolution.com>
1 parent 17f75d5 commit 857947b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

dotenv.sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# See README.md for instructions on setting up the .env file
2+
#
13
RKS_PROJECT_ID=
24

35
RKS_SERVICE_ACCOUNT=
46

57
# You can use \n to separate the lines in your private key
6-
RKS_PRIVATE_KEY=
8+
RKS_PRIVATE_KEY=

quickstart.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ async function getServiceAccessToken() {
5252
}
5353

5454

55-
async function getFromApi(serviceAccessToken, resourceUrl, queryParams = {}, raiseError = true) {
55+
async function getFromApi(serviceAccessToken, resourceUrl, queryParams = null, raiseError = true) {
5656

57-
const url = `${baseUrl}${resourceUrl}`
57+
const queryString = queryParams ? `?${new URLSearchParams(queryParams)}` : '';
58+
const url = `${baseUrl}${resourceUrl}${queryString}`;
59+
5860
const response = await fetch(url, {
5961
headers: {
6062
"Authorization": `Bearer ${serviceAccessToken}`,
6163
"Accept": "application/json",
6264
"Content-Type": "application/json; charset=utf-8"
63-
},
64-
queryParams: queryParams,
65+
}
6566
});
6667

6768
if (!response.ok && raiseError) {
@@ -122,7 +123,7 @@ async function quickstart() {
122123

123124
if (participantIdentifier != "YOUR_PARTICIPANT_IDENTIFIER") {
124125
url = `/api/v1/administration/projects/${rksProjectId}/participants/${participantIdentifier}`;
125-
response = await getFromApi(serviceAccessToken, url, {}, false );
126+
response = await getFromApi(serviceAccessToken, url, null, false );
126127
if (response.status === 404) {
127128
console.log("\nParticipant not found.");
128129
} else {

0 commit comments

Comments
 (0)