Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

If Portrait allows you decide to push your data per API, you have to use the API route /api/sources. This route can automatically decide if an entry needs to be created or updated – as long as the ID is unique – over every source. to configure a source with sourceType: 'api'. These sources can be manually managed through the API.

Create the source in the config

First, you need to create a source in the Configuration. Details API sources

Info

The source name must be in lowercase (wrong: EM2008, correct; em2008)

Example:

Code Block
languageyaml
    - id: em2008
      sourceType: 'api'
      excludeKeysFromSuggestions: [ ]

Manage Entries

Info

The most up-to-date API Specification can always be found on your own instance, either via the openAPI specification or the UI! See API Documentation

Create a new entry

To create an entry, use the following request:

Status
colourYellow
titlePOST
/api/sources/:sourceName

Before you can use this route, you need to create an API source. See here: API Sources

Info

The source name must be in lowercase (wrong: EM2008, correct; em2008)

Request Body:

...

Code Block
languagebash
curl -X 'POST' \
  'http://localhost:8080/api/sources/em2008' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer yourToken' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "GERESP",
    "name": "EM 2008 - Final",
    "data": {
        "key": "GERESP",
        "Opponents": "Germany - Spain",
        "KickOff": "2008-06-29T20:45:00",
        "Result": "0:1",
        "Venue": "Ernst-Happel-Stadion, Vienna",
        "Weather": "Sunny, 27 °C (81 °F), 4% humidity",
        "Referee": "Roberto Rosetti (ITA)",
        "Latitude": "48.207208",
        "Longitude" : "16.420985"
    }
}'
Info

The id attribute has to be unique.

Info

Portrait will throw an 400 Bad Request error in case you try to create an entry with the same ID twice. You either have to delete the old one or call an update request.

Update an existing entry

Status
colourBlue
titlePUT
/api/sources/:sourceName

Code Block
languagebash
curl -X 'PUT' \
  'http://localhost:8080/api/sources/em2008' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer yourToken' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "GERESP",
    "name": "EM 2008 - Final",
    "data": {
        "key": "GERESP",
        "Opponents": "Germany - Spain",
        "KickOff": "2008-06-29T20:45:00",
        "Result": "0:1",
        "Venue": "Ernst-Happel-Stadion, Vienna",
        "Weather": "Sunny, 27 °C (81 °F), 4% humidity",
        "Referee": "Roberto Rosetti (ITA)",
        "Latitude": "48.207208",
        "Longitude" : "16.420985"
    }
}

...

'

Remove an existing entry

Status
colourRed
titleDELETE
/api/sources/:sourceName/:entryID

Code Block
languagebash
curl -X 'DELETE' \
  'http://localhost:8080/api/sources/em2008/GERESP' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer yourToken' \

Remove all entries from an API source

Status
colourPurple
titlePATCH
/api/sources/:sourceName

Code Block
languagebash
curl -X 'PATCH' \
  'http://localhost:8080/api/sources/em2008' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer yourToken' \
Note

Attention! There will be no confirmation for the request.
All data from that source will be gone and can’t be reindexed!