If you decide to push your data per API you have to use the API route /updateIndexEntry
. 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 create an entry Portrait allows you 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 |
---|
|
- 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:
/updateIndexEntry
Request Body: /api/sources/:sourceName
Code Block |
---|
|
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 "indexName(81 °F), 4% humidity",
"Referee": "TickerRoberto Rosetti (ITA)",
"indexTypeLatitude": "NYSE",
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
/api/sources/:sourceName
Code Block |
---|
|
curl -X 'PUT' \
'http://localhost:8080/api/sources/em2008' \
-H 'accept: application/json' \
-H 'Authorization: Bearer yourToken' \
-H 'Content-Type: application/json' \
-d '{
"id": "MSFTGERESP",
"entryNamename": Microsoft"EM 2008 - Final",
Prime USD, "data": {
"IDkey": "BRAGERGERESP",
"_name "Opponents": "BrasilienGermany - DeutschlandSpain",
"DateKickOff": "20142008-07-0806-29T20:45:00",
"Result": "0:1",
"LocationVenue": "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
/api/sources/:sourceName/:entryID
Code Block |
---|
|
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
/api/sources/:sourceName
Code Block |
---|
|
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! |