I’d start with the TestRail API site. The index includes listings with examples of accessing the API.
I’d start with a dummy test case in TestRail to mess with if you can do that. Use that to create the calls you want, then wrap the calls you’re looking for so that you can do something like the pseudo-code below:
// run the test case
// assert something
string Status = MyAssertion.result;
UpdateTestCase("R434", Status);
Then your API code would have a call to POST index.php?/api/v2/add_result/:test_id
and you’d use your data in the call.
You should also check exactly what you’re referring to, since according to the API a test case is not the same as a test, so there might be additional lookups involved.
Exactly how you’d code the connection would depend on what language you’re using as well as how you’re breaking up your tests and test cases. The API docs have detailed instructions for access via Java, PHP, Python, Ruby, and Dot Net (C# or VB.NET)