Pigs public API - technical overview

Created by Sean Schoeman, Modified on Mon, 8 Jul at 1:35 PM by Marina Gherghe

TABLE OF CONTENTS


Authentication

A JWT access token is required to retrieve data from the Pigs public API, this can be retrieved using the  /v1/Authentication/GetAccessToken endpoint. The endpoint will return the access token in the below format.

{
"access_token": "eyJhbGciOiJSUzI1NiIsImtp...",
"token_type": "Bearer",
"expires_in": "3600"
}

This access token should be added to each API call in the "Authorization" header as seen below in curl call:

curl -X GET "https://public-api-pigvision.agrovision.com/v1/Farms/GetFarms" -H "accept: text/plain" -H "Authorization: Bearer eyJhbGciOiJS..."


Usage

All requests require a farmIdentifier to be provided, this can be found using the /v1/farms endpoint.
The /v1/farms will return some identifiable information on the farm (farm name, CPH number (official farm number)) the unique farmIdentifier and the date the farm was last updated.


Each record returned by the API endpoints has an ExternalId that can be used to identify the individual records, these ExternalIds are unique across the entire API.

There are 2 ways to retrieve data from the Pigs public API.


Using the date range endpoints.

These endpoints are ideal for retrieving the data of a new farm or in the case when a full reload is required.

The start and end dates here refer to the event date the farmer enters into their management programs, because of this these endpoints are not suitable for retrieving changes to the data, please use the changes endpoint for retrieving changes.

For performance reasons, you should retrieve data for less than 1 year.


Using the changes endpoint.

This endpoint is used when you have existing farms and want to retrieve changes the farm has made after the specified date.

The date specified here refers to the system date of when the record was modified.

To properly use the changes endpoint it is important to understand the purpose of each property described below.

[
{
//A json serialized string of the latest state of the data record.
"data": "string",

//Relates directly to the data found in the date range endpoints.
//E.g. data retrieved from the /v1/Reproduction/GetWeanings endpoint, will have a
//dataType of "Weaning" in the /v1/changes endpoint.
"dataType": "Weaning",

"changeDateTime": "2024-05-27",
//The system date of the change when it was added to the database.

//The type of change that occurred, specifically "Insert", "Update" or "Delete".
"action": "Insert",

//The unique identifiable ID of the record that has changed.
//This will be the same as the ExternalId in the serialized json and the same as the
//ExternalId returned from the related records date range endpoint.
"externalId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
]

Please note, the changes endpoint will only return the latest state of each data record, i.e. 

  • if there are multiple updates of a record since the specified date, you will see that the record has been updated and the current state of the data.
  • If a record has been created and deleted since the specified date, you will not see this in the endpoint


API endpoints

For information about specific endpoints, please visit the swagger documentation:
https://public-api-pigvision.agrovision.com/swagger/index.html

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article