Difference between revisions of "API Add Project"
From zFairs Contest Management
(Document add project payload and response) |
|||
| Line 1: | Line 1: | ||
| − | == Add Project== | + | == Add Project == |
| − | + | Creates a project (entry) and its participants. At least one participant is required. Optionally attach awards, custom question answers, and files. | |
| − | + | === 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> | <syntaxhighlight lang="JavaScript" line> | ||
| − | |||
fetch('/api/data/project', { | fetch('/api/data/project', { | ||
method:'POST', | method:'POST', | ||
| Line 11: | Line 41: | ||
body: JSON.stringify({ | body: JSON.stringify({ | ||
ApiKey:'<Private key>', | ApiKey:'<Private key>', | ||
| − | FairId: '9df61f13-474b-442f-ac1f-edca7348ef71', // | + | FairId: '9df61f13-474b-442f-ac1f-edca7348ef71', // value of f in your URL |
Body: { | Body: { | ||
| − | Title: | + | Title: "Project Title", // required |
| − | + | CategoryId: 123, // required | |
| − | + | SubCategoryId: 456, // optional | |
| − | + | Plan: "Project plan", | |
| − | + | Abstract: "Abstract text", | |
| − | + | Description: "Description", | |
| − | , | + | ProjectKey: null, // optional GUID; generated if omitted |
| − | + | FixedProjectId: "AB-100", // optional fixed display id | |
| − | + | EntryVideoLink: "https://...", | |
| − | + | EntryVideoLink2: "https://...", | |
| − | + | CategoryAwardId: 1, | |
| − | + | SpecialAwardsIds: [10, 11], | |
| − | + | EntryTypeId: 2, // from Get Info | |
| − | + | Language: "Spanish", | |
| − | ,Participants : [{ | + | InPerson: "Yes", // typically 'Yes' / 'No' |
| − | FirstName: | + | Approved: true, |
| − | + | Participants: [{ // required, at least one | |
| − | + | FirstName: "Alice", // required | |
| − | + | LastName: "Example", // required | |
| − | + | Grade: 8, // required | |
| − | + | TeacherId: "teacher-guid",// required | |
| − | + | SchoolId: 24, // required | |
| − | + | Email: "alice@example.com", | |
| − | + | Phone: "800-000-0000", | |
| − | + | Address: "123 Main St", | |
| − | + | City: "Ogden", | |
| − | + | State: "UT", | |
| − | + | Zip: "84401", | |
| − | + | Language: "Spanish", | |
| − | , | + | Id: null, // optional existing person GUID |
| − | + | Username: null, | |
| − | + | Password: null, | |
| − | + | ProfilePicture: { | |
| − | + | Base64String: "iVBORw0KGgo...", | |
| − | + | FileName: "profile.png", | |
| − | Base64String: | + | Caption: "Portrait" |
| − | |||
| − | |||
} | } | ||
| − | |||
}], | }], | ||
| − | + | CustomQuestions: [{ Id: 55, Value: "large" }], | |
| − | + | Files: [{ | |
| − | + | Base64String: "iVBORw0KGgo...", // or DownloadFromUrl | |
| − | + | DownloadFromUrl: null, | |
| − | + | FileName: "board.png", | |
| − | + | Caption: "Display board", | |
| − | + | PaperworkFileType: null // set for paperwork PDFs; id from Get Info | |
| − | + | }] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
}) | }) | ||
| Line 82: | Line 95: | ||
.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: | ||
| − | + | <pre> | |
| − | + | { | |
| + | Success: true, | ||
| + | Message: null, // may include award/file warnings | ||
| + | Body: { | ||
| + | ProjectKey: "generated-or-provided-guid", | ||
| + | ProjectId: "AB-100", | ||
| + | InterviewRoomUrl: "https://yoursite/app/video/...", // when virtual interviews enabled | ||
| + | Title: "Project Title", | ||
| + | Participants: [ /* with assigned Id/Username */ ], | ||
| + | ... | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| − | |||
| + | === Field notes === | ||
| + | * Participant is required — empty <code>Participants</code> returns an error. | ||
| + | * Team project flag is set automatically when there is more than one participant. | ||
| + | * Prefer [[API Update Project]] to change an existing project (requires <code>ProjectKey</code>). | ||
| + | * File uploads accept Base64 or <code>DownloadFromUrl</code>. Paperwork should be PDF with <code>PaperworkFileType</code> from [[API Get Info]]. | ||
| + | * Lookup ids (category, awards, entry type, custom questions, paperwork types) come from [[API Get Info]]. | ||
| − | |||
| + | === Related APIs === | ||
| + | * [[API Update Project]] | ||
| + | * [[API Get Projects]] | ||
| + | * [[API Get Info]] | ||
| + | * [[API Upload Project Assets]] | ||
| + | * [[API Set Project Id]] | ||
| − | + | <br/><br/> | |
[[Category: API]] | [[Category: API]] | ||
Revision as of 12:49, 25 July 2026
Contents
Add Project
Creates a project (entry) and its participants. At least one participant is required. Optionally attach awards, custom question answers, and files.
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/project', {
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: {
Title: "Project Title", // required
CategoryId: 123, // required
SubCategoryId: 456, // optional
Plan: "Project plan",
Abstract: "Abstract text",
Description: "Description",
ProjectKey: null, // optional GUID; generated if omitted
FixedProjectId: "AB-100", // optional fixed display id
EntryVideoLink: "https://...",
EntryVideoLink2: "https://...",
CategoryAwardId: 1,
SpecialAwardsIds: [10, 11],
EntryTypeId: 2, // from Get Info
Language: "Spanish",
InPerson: "Yes", // typically 'Yes' / 'No'
Approved: true,
Participants: [{ // required, at least one
FirstName: "Alice", // required
LastName: "Example", // required
Grade: 8, // required
TeacherId: "teacher-guid",// required
SchoolId: 24, // required
Email: "alice@example.com",
Phone: "800-000-0000",
Address: "123 Main St",
City: "Ogden",
State: "UT",
Zip: "84401",
Language: "Spanish",
Id: null, // optional existing person GUID
Username: null,
Password: null,
ProfilePicture: {
Base64String: "iVBORw0KGgo...",
FileName: "profile.png",
Caption: "Portrait"
}
}],
CustomQuestions: [{ Id: 55, Value: "large" }],
Files: [{
Base64String: "iVBORw0KGgo...", // or DownloadFromUrl
DownloadFromUrl: null,
FileName: "board.png",
Caption: "Display board",
PaperworkFileType: null // set for paperwork PDFs; id from Get Info
}]
}
})
})
.then(response => response.json())
.then(data=>{console.log('Success: ',data);})
.catch((error)=>{console.log('Error: ', error);});Response
On success:
{
Success: true,
Message: null, // may include award/file warnings
Body: {
ProjectKey: "generated-or-provided-guid",
ProjectId: "AB-100",
InterviewRoomUrl: "https://yoursite/app/video/...", // when virtual interviews enabled
Title: "Project Title",
Participants: [ /* with assigned Id/Username */ ],
...
}
}
Field notes
- Participant is required — empty
Participantsreturns an error. - Team project flag is set automatically when there is more than one participant.
- Prefer API Update Project to change an existing project (requires
ProjectKey). - File uploads accept Base64 or
DownloadFromUrl. Paperwork should be PDF withPaperworkFileTypefrom API Get Info. - Lookup ids (category, awards, entry type, custom questions, paperwork types) come from API Get Info.
Related APIs