API Add School: Difference between revisions
From zFairs Contest Management
No edit summary |
Document add/update school fields |
||
| Line 1: | Line 1: | ||
== Add | == Add School == | ||
Creates or updates a school on the client. If <code>Id</code> is set to an existing school id, the school is updated; otherwise a new school is created. | |||
=== Authentication === | |||
All data API calls are <code>POST</code> (unless noted) with JSON body: | |||
{| class="wikitable" | |||
|- | |||
! Field !! Required !! Description | |||
|- | |||
| <code>ApiKey</code> || Yes* || Private API key for your site. Prefer this over username/password. | |||
|- | |||
| <code>Username</code> / <code>Password</code> || Yes* || Alternate auth if not using ApiKey. | |||
|- | |||
| <code>FairId</code> || Yes || Fair GUID from the site URL (<code>f</code> query parameter). | |||
|- | |||
| <code>Body</code> || Depends || Request payload. Use <code>{}</code> when no body fields are needed. | |||
|} | |||
* Provide '''either''' <code>ApiKey</code> '''or''' <code>Username</code>+<code>Password</code>. | |||
< | Calls must be run '''server-side''' — do not expose your API key in a browser. | ||
=== Response envelope === | |||
Most endpoints return: | |||
<pre> | |||
{ | |||
Success: true, | |||
Message: null, // error text when Success is false | |||
Body: { ... } // endpoint-specific payload | |||
} | |||
</pre> | |||
=== Request === | |||
<syntaxhighlight lang="JavaScript" line> | |||
fetch('/api/data/school', { | |||
method:'POST', | |||
headers:{'Content-Type': 'application/json'}, | |||
body: JSON.stringify({ | |||
ApiKey:'<Private key>', | |||
FairId: '9df61f13-474b-442f-ac1f-edca7348ef71', // value of f in your URL | |||
Body: { | |||
Id: 0, // 0 or omit for new; existing id to update | |||
Name: "Example School", | |||
Address: "100 School Rd", | |||
Address2: "", | |||
City: "Ogden", | |||
State: "UT", | |||
Zip: "84401", | |||
County: "Weber", | |||
Phone: "801-555-0100", | |||
WebsiteUrl: "https://example.edu", | |||
SchoolType: "Public", // Public | Private | Charter | Home | |||
PrincipalName: "Pat Principal", | |||
PrincipalPhone: "801-555-0101", | |||
PrincipalEmail: "principal@example.edu", | |||
ContactFirstName: "Casey", | |||
ContactLastName: "Contact", | |||
ContactPhone: "801-555-0102", | |||
ContactEmail: "contact@example.edu", | |||
GradeLow: 6, | |||
GradeHigh: 12, | |||
Fax: "", | |||
SchoolPaysFees: false, | |||
IsFeeWaiverSchool: false, | |||
SchoolCode: "EX001", | |||
Active: true, | |||
Affiliated: true, | |||
RegionName: "North", | |||
EducationAgencyName: "North Agency" | |||
} | |||
}) | |||
}) | |||
.then(response => response.json()) | |||
.then(data=>{console.log('Success: ',data);}) | |||
.catch((error)=>{console.log('Error: ', error);}); | |||
</syntaxhighlight> | |||
=== Response === | |||
On success <code>Body</code> is the school object with <code>Id</code> populated: | |||
<pre> | |||
{ | |||
Success: true, | |||
Message: null, | |||
Body: { Id: 24, Name: "Example School", ... } | |||
} | |||
</pre> | |||
=== Field notes === | |||
* <code>SchoolType</code> maps to: Public → "Public School", Private → "Private School", Charter → "Charter School", Home → "Home School". Unknown defaults to Public School. | |||
* Returned <code>Id</code> should be stored for use as <code>SchoolId</code> on projects/participants. | |||
=== Related APIs === | |||
* [[API Get Schools]] | |||
* [[API Add Project]] / [[API Add Person]] | |||
<br/><br/> | |||
[[Category: API]] | [[Category: API]] | ||
Revision as of 11:49, 25 July 2026
Add School
Creates or updates a school on the client. If Id is set to an existing school id, the school is updated; otherwise a new school is created.
Authentication
All data API calls are POST (unless noted) with JSON body:
| Field | Required | Description |
|---|---|---|
ApiKey |
Yes* | Private API key for your site. Prefer this over username/password. |
Username / Password |
Yes* | Alternate auth if not using ApiKey. |
FairId |
Yes | Fair GUID from the site URL (f query parameter).
|
Body |
Depends | Request payload. Use {} when no body fields are needed.
|
- Provide either
ApiKeyorUsername+Password.
Calls must be run server-side — do not expose your API key in a browser.
Response envelope
Most endpoints return:
{
Success: true,
Message: null, // error text when Success is false
Body: { ... } // endpoint-specific payload
}
Request
fetch('/api/data/school', {
method:'POST',
headers:{'Content-Type': 'application/json'},
body: JSON.stringify({
ApiKey:'<Private key>',
FairId: '9df61f13-474b-442f-ac1f-edca7348ef71', // value of f in your URL
Body: {
Id: 0, // 0 or omit for new; existing id to update
Name: "Example School",
Address: "100 School Rd",
Address2: "",
City: "Ogden",
State: "UT",
Zip: "84401",
County: "Weber",
Phone: "801-555-0100",
WebsiteUrl: "https://example.edu",
SchoolType: "Public", // Public | Private | Charter | Home
PrincipalName: "Pat Principal",
PrincipalPhone: "801-555-0101",
PrincipalEmail: "principal@example.edu",
ContactFirstName: "Casey",
ContactLastName: "Contact",
ContactPhone: "801-555-0102",
ContactEmail: "contact@example.edu",
GradeLow: 6,
GradeHigh: 12,
Fax: "",
SchoolPaysFees: false,
IsFeeWaiverSchool: false,
SchoolCode: "EX001",
Active: true,
Affiliated: true,
RegionName: "North",
EducationAgencyName: "North Agency"
}
})
})
.then(response => response.json())
.then(data=>{console.log('Success: ',data);})
.catch((error)=>{console.log('Error: ', error);});Response
On success Body is the school object with Id populated:
{
Success: true,
Message: null,
Body: { Id: 24, Name: "Example School", ... }
}
Field notes
SchoolTypemaps to: Public → "Public School", Private → "Private School", Charter → "Charter School", Home → "Home School". Unknown defaults to Public School.- Returned
Idshould be stored for use asSchoolIdon projects/participants.
Related APIs