Submitting P5 Files |
|
MRR data formatted in the P5 file format can be submitted from P5 or by using the PTAGIS web API. The API includes two endpoints (load and correct) for submitting P5 files in a RESTful manner.
To submit files using the PTAGIS API, data contributors will need to do the following:
1.Contact PTAGIS to obtain an API key used for authorization.
1.Build a properly formatted P5 file.
2.Use the /submissions/mrr/authorize endpoint to request authorization to submit a file (described below).
3.Use the JSON web token (JWT) returned from the call in #3 with the appropriate /submissions/mrr endpoint to either load or correct the file (see sample code).
4.Use the /submissions/mrr/{id} endpoint with the Submission ID to request the status of the file after it has been processed.
If you plan to build an application to submit P5 files using the web API, you should use the Test API (https://testapi.ptagis.org) while developing and testing the application. Files submitted using the Test API will be processed using the test system and will not be loaded into the production database.
The /submissions/mrr/authorize call requires the following in the request body:
•API Key: a GUID assigned to you (contact PTAGIS to receive one)
•One or more MRR Project codes: the 3-character MRR Project code of the file(s) that will be submitted
•Registered Email Address: an email address registered with PTAGIS and allowed to submit data for the MRR Project code(s)
Sample Code
The following C# sample code shows how to include the JWT returned from the authorize endpoint in the subsequent call to submit the data to PTAGIS.
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
//NOTE: using test API endpoint
var apiUrl = "https://testapi.ptagis.org/submissions/mrr/load";
var jwtToken = "your_jwt_token_here";
var p5FilePath = "path/to/your/P5/file/TST-2025-120-002.json";
using var httpClient = new HttpClient();
// Add the JWT token to the Authorization header
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
// Prepare the multipart form data content
using var form = new MultipartFormDataContent();
using var fileStream = File.OpenRead(p5FilePath);
var fileContent = new StreamContent(fileStream);
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Add the file content to the form data
form.Add(fileContent, "file", Path.GetFileName(p5FilePath));
// Send the POST request
var response = await httpClient.PostAsync(apiUrl, form);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("JSON file uploaded successfully!");
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
else
{
Console.WriteLine($"Upload failed: {response.StatusCode}");
var error = await response.Content.ReadAsStringAsync();
Console.WriteLine(error);
}
}
}
File Load Status Response
After the file is accepted for processing, the submissions/mrr/{id} endpoint can be used to request the status of the file. Possible responses are shown below:
Response |
Definition |
Pending |
File has not been processed. |
Rejected |
The file was not loaded because it did not pass data validation or file format requirements. More information can be found in the Message element of the response. |
Failed |
An unanticipated error occurred during file processing. Please contact PTAGIS for more information. |
Loaded |
First successful load of a data file with this name. |
Corrected |
A new version of the file was loaded successfully, replacing data from the previous version of the file. |
Provisional |
Data in the file was loaded or corrected, but there were duplicate records, test tags or some other condition that should be reviewed, and corrected if necessary. |