API Overview


This API can query most of information needed by the TAC statistics page, more query fields will be added as they are needed by the TAC Process or any other application that might need to use it.
Some Query fields might change in time to best fit what will be confirmed as effective by anyone or any application using it and not affecting any application that is already using this API.

What is GraphQL?

Please refer to official website for more


How to use this API

.
For development purposes graphiql is enabled, which will help you see the structure of the API and what you can query for, which will require your web manager username and password to login. For production users must go to /token with a json object having username and password fields like {"usename": "WMUser", "password":"password"}to get a user Token which need to be included as a header in all queries to API. header name:- Authorization: Token user token.

API Development screen is normally divided into two sections and the third section can be added by clicking Docs button at top right of the screen.
  • First section: This is for writing your query.

    A graphQL query is like defining a structure of your json object.

    Sample query

    Querying for number of visits, ra and dec for 2017-1 targets.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    {
    targets(semester: "2017-1"){
    NVisits
    target{
    targetcoordinates{
    ra
    dec
    }
    }
    }
    }
    line 2: it will return the list of all 2017-2 targets
    line 3: number of visits for each target
    line 4-7: due to SDB structure, to get more details of the target. Click on Target field where there is a link to target Coordinates field where there are RA and DEC of that target
    To avoid Line 4-7 the auto mapping of the SDB don't have to map everything
  • Second section: This section is for query results.
    GraphQL will return a json object of data with the structure you defined on your query section or json object of errors.
    Sample results for the above query
    {
    "data": {
    "targets": [
    {
    "NVisits": 1,
    "target": {
    "targetcoordinates": {
    "dec": x.x,
    "ra": x.x
    }
    }
    },
    {
    "NVisits": 2,
    "target": {
    "targetcoordinates": {
    "dec": x.x,
    "ra": x.x
    }
    }
    },
    .
    .
    .
  • Third section: To see the depth of what you can query and the structure of API.
    This section will guide you in writing a GraphQL query and it will also show data type of what you are querying. Start by clickingQuery this will lead you to what you can query in a root field.

    How above query was created.
    1. Select Docs for Documentation Explorer
    2. Select Query to root query,
      A list of field will appear, this will be what can be queried on this field.
      • Look for field/s of interest in this case targets.
        targets(semester: String): [ProposalTarget]
      • targets require argument ("semester: String") which means you must provide a semester of type string when you are querying for targets
      • "[ProposalTarget]" square brackets means you will get a list of what is defined within it, in this case you will get a list of ProposalTarget
    3. Select ProposalTarget to see what fields it contains.
      • One of the fields of ProposalTarget is of interest, which is NVisits of type INT. It is then added to the query
      • RA and DEC are in target: Target Field in target >> targetcoordinates >> ra and dec which are float

For Production

Users need to get a token and use it as described above. To get data from the API user will have to go to GraphQL End-point with the query included in the uri like http://tacapi.cape.saao.ac.za/graphiql?query={targets(semester: "2017-1"){NVisits target{targetcoordinates{ra dec}}}} the results of the above query will either be errors or data.
errors will have massage field that explains what kind of error it is or where the error is happening
data the results from a successful query.