GraphQL
Query and change AgriWebb farm data with GraphQL.
Opening https://api.agriwebb.com/v2 in a browser loads Apollo Sandbox, where you can try queries and mutations against the API. In the Headers tab of the Operation panel, add the header for the credential you were issued:
- an OAuth 2.0 access token:
Authorizationwith the valueBearer {access token} - an API key:
x-api-keywith the key as the value
Every query, mutation and type is documented in the GraphQL section of the sidebar, for example the farms query.
Errors
An error in any field fails the whole request, and data is null. When errors of different kinds occur, the most severe sets the HTTP status, in the order 500, 401, 403, 404, 400. errors holds only the errors of that kind, and error is the first one's message.
Common API calls
Geo coordinate order
The GraphQL API follows the GeoJSON standard for all coordinates and geometries. GeoJSON orders coordinates longitude, latitude, the reverse of many other tools. See lon lat lon lat for which tools use which order.
If a map feature created through the API doesn't appear on the farm map, check the coordinate order first: a feature sent as latitude, longitude lands somewhere else entirely. This mutation creates a rain gauge on the Sydney Opera House, at longitude 151.2152967, latitude -33.8567844:
mutation($farmId: ID!) { addMapFeatures(input:{ name: "Opera house" geometry: { type: Point coordinates: [151.2152967, -33.8567844] } farmId: $farmId type: RAIN_GAUGE }) { mapFeatures { id } } }Accessing animal records
An animal's history is a series of records. records returns the Record interface, so select the fields of each record type with an inline fragment:
query($farmId: String!, $animalId: String!) { animals( farmId: $farmId filter: { animalId: { _eq: $animalId } } ) { animalId records { recordId recordType ... on WeighRecord { weight { unit value } } ... on ScoreRecord { score { unit value } } } } }x-api-key?stringAn API key issued by AgriWebb. Send this or Authorization.
- body
query*stringoperationName?stringvariables?The query or mutation succeeded, and data holds its result.
application/json- response
data?unknownerrors?array<unknown>error?unknowncurl -X POST "https://example.com/v2" \ -H "Content-Type: application/json" \ -d '{ "query": "string" }'{ "data": null, "errors": [ null ], "error": null}