API Add School: Difference between revisions

From zFairs Contest Management
No edit summary
Remove username/password API auth; ApiKey only
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== 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.
|-
| <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.
|}
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>
<syntaxhighlight lang="JavaScript" line>
fetch('/api/data/school', {
fetch('/api/data/school', {
     method:'POST',
     method:'POST',
     headers:{'Content-Type': 'application/json'},
     headers:{'Content-Type': 'application/json'},
     body: JSON.stringify({
     body: JSON.stringify({
             Username:'admin username',
             ApiKey:'<Private key>',
             Password: 'password',
             FairId: '9df61f13-474b-442f-ac1f-edca7348ef71', // value of f in your URL
             Body: {
             Body: {
                Name: '_ A Test School'
Id: 0,  // 0 or omit for new; existing id to update
                ,Address: '1219 34th State'
Name: "Example School",
                ,Address2: 'Apt 3'
Address: "100 School Rd",
                ,City: 'Ogden'
Address2: "",
                ,State: 'Ut'
City: "Ogden",
                ,Zip: '84403'
State: "UT",
                ,County: 'Weber'
Zip: "84401",
                ,Phone: '801-252-0903'
County: "Weber",
                ,WebsiteUrl: 'zfairs.com'
Phone: "801-555-0100",
                ,SchoolType: 'Public' //{ Public, Private, Charter, Home}
WebsiteUrl: "https://example.edu",
                ,PrincipalName: 'Mrs Bell'
SchoolType: "Public",  // Public | Private | Charter | Home
                ,PrincipalPhone: '801-252-0000'
PrincipalName: "Pat Principal",
                ,PrincipalEmail: 'MrsBell@zfairs.com'
PrincipalPhone: "801-555-0101",
                ,ContactFirstName: 'Joe'
PrincipalEmail: "principal@example.edu",
                ,ContactLastName: 'Homes'
ContactFirstName: "Casey",
                ,ContactPhone: '801-252-0001'
ContactLastName: "Contact",
                ,ContactEmail: 'jh@zfairs.com'
ContactPhone: "801-555-0102",
                ,GradeLow: '0' //pre-k = -1, k = 0
ContactEmail: "contact@example.edu",
                ,GradeHigh: '12'
GradeLow: 6,
                ,Fax: '801-252-0003'
GradeHigh: 12,
            }
Fax: "",
SchoolPaysFees: false,
IsFeeWaiverSchool: false,
SchoolCode: "EX001",
Active: true,
Affiliated: true,
RegionName: "North",
EducationAgencyName: "North Agency"
}
         })
         })
})
})
Line 36: Line 74:
.then(data=>{console.log('Success: ',data);})
.then(data=>{console.log('Success: ',data);})
.catch((error)=>{console.log('Error: ', error);});
.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]]


</syntaxhighlight>
<br/><br/>
[[Category: API]]

Latest revision as of 11:55, 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.
FairId Yes Fair GUID from the site URL (f query parameter).
Body Depends Request payload. Use {} when no body fields are needed.


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

  • SchoolType maps to: Public → "Public School", Private → "Private School", Charter → "Charter School", Home → "Home School". Unknown defaults to Public School.
  • Returned Id should be stored for use as SchoolId on projects/participants.