TracCloudTechAPI: Difference between revisions

From Redrock Wiki

(Undo revision 10374 by Redrock (talk))
Tags: Undo Reverted
(Blanked the page)
Tags: Blanking Manual revert Reverted
Line 1: Line 1:
=== '''TracCloud API Documentation''' ===


This page contains data on TracCloud's v1 API support. This page will be updated with more information over time.
<hr>
<!--------------------------------------- Sending requests --------------------------------------->
<!--<div style="float: left; margin-top: 0em; margin-bottom: 1em"><big><b>Sending Requests</b></big></div><div class="mw-collapsible mw-collapsed">-->
<big><b>Sending Requests</b></big>
The URL for the API is: https://traccloud.go-redrock.com/demo/app/webhook.php (replace 'demo' with your campus code, or replace traccloud.go-redrock.com/demo with your custom URL if applicable).<br><br>
For testing purposes, you can send the request from a browser's network tab like this.
[[File:9989368.png|1000px]]<br><br>
That same request with curl looks like this. The rest of this article will use curl. Most of the examples will include line breaks for readability, it will work either way.
[[File:1179363.png|1000px]]
<!--</div>-->
<hr>
<!--------------------------------------- Updating Records --------------------------------------->
<!--<div style="float: left; margin-top: 0em; margin-bottom: 1em"><big><b>Updating Records (Action: update, store, create)</b></big></div><div class="mw-collapsible mw-collapsed">-->
<big><b>Updating Records (Action: update, store, create)</b></big>
pass a parameter named "data" in the following format:<br>
<syntaxhighlight lang="json" style="border: 1px dashed black">
data={"action": "update", "APIKey": "YOUR_API_KEY", "KeyID": 1910,  "table": "Students", "Last_Name": "Halsteader"}
</syntaxhighlight><br>
The response should be:
<syntaxhighlight lang="json" style="border: 1px dashed black">
{"status":"success","message":"data Students record updated #1910","data":{"Sequence":1910}}
</syntaxhighlight><br>
Example curl command.
<syntaxhighlight lang="bash" style="border: 1px dashed black">
curl -d 'data={
"action": "update",
"APIKey": "YOUR_API_KEY",
"KeyID": 1931,
"table": "Students",
"Last_Name": "Smith"
}' https://traccloud.go-redrock.com/demo/app/webhook.php
</syntaxhighlight><br>
Available fields and their options:
* <b>action</b>
::<b>update</b> will update an existing record, if you try updating when the record does not exist, it will return an error.
::<b>store</b> will update records, or create records if a record doesn't exist.
::<b>create</b> will create the currently non-existent record. If you try creating when the KeyID already exists, it will return an error.<br><br>
* <b>APIKey</b>
::The API key.<br><br>
* <b>KeyID</b>
::Provide the sequence number of the record being modified.<br><br>
* <b>table</b>
::Provide the table of the record being modified (Students, Registrations, etc).<br><br>
* <b>[field]</b>
::Provide the field you want to modify (e.g., Last_Name) as well as the value you want to set it to.<br><br>
<!--</div>-->
<hr>
<!--------------------------------------- Query --------------------------------------->
<!--<div style="float: left; margin-top: 0em; margin-bottom: 1em"><big><b>Retrieving Records (Action: query)</b></big></div><div class="mw-collapsible mw-collapsed">-->
<big><b>Retrieving Records (Action: query)</b></big>
The next API action is “query”, which can be used to retrieve fields from records. Here's an example that finds 20 students who's ID is greater than 1.
<syntaxhighlight lang="json" style="border: 1px dashed black">
curl -d 'data={
    "action": "query",
    "from": "students",
    "page": 1,
    "page_recs": 20,
    "APIKey": "YOUR_API_KEY",
    "fields": ["Sequence", "First_Name", "Last_Name"],
    "order": "first_name ASC",
"query": {
"fields": [{
            "field": "Sequence",
    "value": "1",
    "op": ">"
        }]
    }
}' https://traccloud.go-redrock.com/demo/app/webhook.php
</syntaxhighlight><br>
This query will return the following.
<syntaxhighlight lang="json" style="border: 1px dashed black">
{"status":"success","message":"data queried","data":
[{"Sequence":1901,"First_Name":"Jackson","Last_Name":"Gomez-Lopez"},
{"Sequence":1910,"First_Name":"Angi","Last_Name":"Halsteader"},
{"Sequence":1911,"First_Name":"Ou00edhare","Last_Name":"Wallace"},
{"Sequence":1912,"First_Name":"Joe","Last_Name":"BarraganIII"},
{"Sequence":1913,"First_Name":"Lori","Last_Name":"Train"},
{"Sequence":1914,"First_Name":"John","Last_Name":"Cunningham"},
{"Sequence":1915,"First_Name":"Jaime","Last_Name":"Tsosie"},
{"Sequence":1916,"First_Name":"David","Last_Name":"Perry"},
{"Sequence":1917,"First_Name":"Luis","Last_Name":"Frias"},
{"Sequence":1918,"First_Name":"Freida","Last_Name":"Miller"},
{"Sequence":1919,"First_Name":"Andre","Last_Name":"Davis"},
{"Sequence":1920,"First_Name":"Alyssa","Last_Name":"Gumeringer"},
{"Sequence":1921,"First_Name":"Nils","Last_Name":"Christianson"},
{"Sequence":1922,"First_Name":"Jeanne","Last_Name":"Patterson"},
{"Sequence":1923,"First_Name":"Rachelle","Last_Name":"Rodriguez"},
{"Sequence":1924,"First_Name":"Damian","Last_Name":"Garcia"},
{"Sequence":1926,"First_Name":"Brandi","Last_Name":"Clee"},
{"Sequence":1927,"First_Name":"Edward","Last_Name":"Ireland"},
{"Sequence":1928,"First_Name":"Nicole","Last_Name":"Love-Cleasby"},
{"Sequence":1929,"First_Name":"Liam","Last_Name":"Howlett"}]}
</syntaxhighlight><br>
* <b>Action</b>
::Should be "Query", otherwise review the previous section of this article.<br><br>
* <b>from</b>
::The table you wish to retrieve data from (Students, Visits, etc).<br><br>
* <b>page</b>
::The page number to get records from, similar to pages on listings. This attribute allows you to write a program that continues hitting the server 1 page at a time getting the number of records in page_recs at a time. The programmer would pass 1 as page the first time, get the results and process, then pass 2 as page, etc, until the number of recs is less than the amount in page_recs.<br><br>
* <b>page_recs</b> (Optional, seems to default to 20)
::The quantity of records to return.<br><br>
* <b>APIKey</b>
::The API key.<br><br>
* <b>fields</b>
::The fields you want to display from the records you're retrieving. Twig tags can be used. Center.Name, etc.<br><br>
* <b>order</b>
::How data is sorted. Choose a field, and sort ascending (ASC) or descending (DESC).<br><br>
* <b>Query</b>
::* <b>Query type</b>
::::Detailed further into this article.
::* <b>field</b>
::::Choose the field you want to search by.
::* <b>value</b>
::::The value you want to search by.
::* <b>op</b> (use | for "or")
::::<b>=</b> - Equals.
::::<b>!=</b> - Not.
::::<b>></b> - Greater than.
::::<b><</b> - Less than.
::::<b><=</b> - Less than or equal to.
::::<b>>=</b> - Greater than or equal to.
::::<b>LIKE</b> - Similar to, use % as a wildcard.
::::<b>NOT LIKE</b> - Similar to, use % as a wildcard.
==Query Options==
The examples below only include the "Query" portion of the data for brevity. These can be copied into the example curl command from earlier in this section.
<b>fields</b> | Search for specific values, using additional operators if needed.
<syntaxhighlight lang="json" style="border: 1px dashed black">
"query": {
"fields": [{
            "field": "ID",
    "value": "1933",
    "op": "="
        }]
    }
</syntaxhighlight><br>
<b>orfields</b> | Search for records that match any of the listed criteria. This can include an unlimited number of fields.
<syntaxhighlight lang="json" style="border: 1px dashed black">
    "query": {
        "orfields": [
            {
                "field": "First_Name",
                "value": "%",
                "op": "LIKE"
            },
            {
                "field": "Last_Name",
                "value": "%e%|%i%|%son",
                "op": "LIKE"
            },
            {
                "field": "Major",
                "value": "Biology",
                "op": "!="
            }
        ]
    }
</syntaxhighlight><br>
<b>andfields</b> | Search for records that match all of the listed criteria. This can include an unlimited number of fields.
<syntaxhighlight lang="json" style="border: 1px dashed black">
    "query": {
        "andfields": [
            {
                "field": "First_Name",
                "value": "Rob",
                "op": "="
            },
            {
                "field": "Last_Name",
                "value": "S%",
                "op": "LIKE"
            },
            {
                "field": "Major",
                "value": "Biology",
                "op": "="
            }
        ]
    }
</syntaxhighlight><br>
<b>or</b> | Used to combine 2 (and only 2) instances of andfields/orfields. Records are returned if either criteria is met.
<syntaxhighlight lang="json" style="border: 1px dashed black">
        "or": [
            {
                "andfields": [
                    {
                        "field": "Sequence",
                        "value": "1",
                        "op": ">"
                    },
                    {
                        "field": "Sequence",
                        "value": "1000000",
                        "op": "<"
                    }
                ]
            },
            {
                "orfields": [
                    {
                        "field": "First_Name",
                        "value": "%",
                        "op": "LIKE"
                    },
                    {
                        "field": "Last_Name",
                        "value": "%e%|%i%|%son",
                        "op": "LIKE"
                    }
                ]
            }
        ]
    }
</syntaxhighlight><br>
<b>and</b> | Used to combine 2 (and only 2) instances of andfields/orfields. Records are returned if both criteria are met.
<syntaxhighlight lang="json" style="border: 1px dashed black">
    "query": {
        "and": [
            {
                "andfields": [
                    {
                        "field": "Sequence",
                        "value": "1",
                        "op": ">"
                    },
                    {
                        "field": "Sequence",
                        "value": "1000000",
                        "op": "<"
                    }
                ]
            },
            {
                "orfields": [
                    {
                        "field": "TimeIn",
                        "value": "{{\"now\"|date_modify(\"-7 days\")|date(\"Y-m-d H:i:s\")}}",
                        "op": ">"
                    },
                    {
                        "field": "Last_Name",
                        "value": "%e%|%i%|%son",
                        "op": "LIKE"
                    }
                ]
            }
        ]
    }
</syntaxhighlight>
<!--</div>-->
<hr>

Revision as of 16:58, 3 July 2024