As SRGSSR, we always try new technologies for providing state-of-the-art experience for both internal and external developers. With the Publication Data Platform (PDP), we collect and correlate publication relevant metadata from various systems like EPG, CMS, archives and online media channels (e.g. Play). We provide access to these vast amount of metadata through our new PDP API as a GraphQL interface. Although the API is in early stage, we want you to try it out as one of the very first and give feedback! For the Hackdays, we have included SRF and RTR archive data with the access point described below. The API will be released on the SRG Developer Portal in the near future.
Feel free to give me feedback on whether you want to see more of this approach to access data from SRGSSR and also on how to improve.
Have fun,
Romain Haenni, Product Owner, romain.haenni@srgssr.ch
Usage
Basic authentication
Credentials will be revoked soon after the SRG Hackdays:
user: hackdays_2021
password: PRM2cgg99SbGtQwnZHl0deVET9uwzH
Access with curl
curl --header "Content-Type: application/json" \
--user hackdays_2021:PRM2cgg99SbGtQwnZHl0deVET9uwzH \
--request POST \
--data '{"query":"{faroItems(first: 3) { edges { title }} }"}' \
https://graphql-api.pdp.dev.srgssr.ch/graphql
|
Example Queries
Simple Query
{
faroItems(first: 3) {
edges {
title
}
}
}
|
Query for fetching items
query {
faroItems(first: 10, after: "MDAwMDM1NjUtMzczMy00ZjY3LTgwOTUtZDExNTZjNmM4OWYw") {
edges {
program {
businessUnit
mediaType
showName
date
moderators {
firstName
lastName
}
}
title
description
playLinks
persons {
firstName
lastName
role
}
descriptorPaths
}
cursor
}
}
|
Curl Example
curl --header "Content-Type: application/json" \
--user hackdays_2021:PRM2cgg99SbGtQwnZHl0deVET9uwzH \
--request POST \
--data '{"query":"{faroItems(first: 3) { edges { title } cursor }}"}' \
https://graphql-api.pdp.dev.srgssr.ch/graphql
result:
{
"data": {
"faroItems": {
"edges": [
{
"title": "EW Ferrera"
},
{
"title": "Gotthard-Basistunnel als Bauwerk der Superlative"
},
{
"title": "Wahl Leuenberger"
}
],
"cursor": "MDAwMDU0MTYtODdhYy00ZDNmLWE1YTctZTQ4MjJlYzkyOWQ0"
}
}
}
|
Paginating with Cursors
curl --header "Content-Type: application/json" \
--user hackdays_2021:PRM2cgg99SbGtQwnZHl0deVET9uwzH \
--request POST \
--data '{"query":"{faroItems(first: 3, after: \"MDAwMDU0MTYtODdhYy00ZDNmLWE1YTctZTQ4MjJlYzkyOWQ0\") { edges { title } cursor }}"}' \
https://graphql-api.pdp.dev.srgssr.ch/graphql
result:
{
"data": {
"faroItems": {
"edges": [
{
"title": "Nationalpark-Serie \\\"Il parc naziunal svizzer\\\" (1)"
},
{
"title": "Puls-mix"
},
{
"title": "Seeland Bank"
}
],
"cursor": "MDAwMTkwYTctNmM2Ni00MjlmLWI3Y2EtN2NlNDUxNThiOWQ3"
}
}
}
|
Schema
type FaroItem {
id: String!
programId: String!
itemNr: Int!
mediaUrns: [String!]!
playLinks: [String!]!
descriptorPaths: [String!]!
program: FaroProgram
title: String
producer: String
description: String
descriptor: String
sportDoc: FaroSportDoc!
persons: [Person!]!
}
type FaroItemPage {
edges: [FaroItem!]!
cursor: String
}
type FaroModerator {
firstName: String
lastName: String
}
type FaroProgram {
id: String!
businessUnit: String
mediaType: String
episodeIds: [String!]!
date: String
showName: String
title: String
seriesNr: Int
moderators: [FaroModerator!]!
}
type FaroSportDoc {
season: String
sportEventPaths: [String!]!
sportPaths: [String!]!
}
type Person {
firstName: String
lastName: String
aliasFirstName: String
aliasLastName: String
role: String
}
type Query {
faroItems(first: Int!, after: String): FaroItemPage!
}
|
Access with PDP python library
pip install srgssr-publication-data-api
Authentication
from
sgqlc.types import
Variable, non_null
from
srgssr_publication_data_api import
PublicationDataApi
# replace url, username, password with real values
client =
PublicationDataApi('
https://graphql-api.pdp.dev.srgssr.ch/graphql'
, hackdays_2021', 'PRM2cgg99SbGtQwnZHl0deVET9uwzH')
op =
client.query_op()
# to restrict fields to just title and cursor (for pagination):
selector =
op.faro_items(first=5)
selector.edges().title()
selector.cursor()
# if you just want to see the schema, just remove the selector.
result =
client.run_query(op)
print(result)
Set the user environment variables:
export PDP_API=https://graphql-api.pdp.dev.srgssr.ch/graphql
export USER_NAME=hackdays_2021
export USER_PASSWORD=PRM2cgg99SbGtQwnZHl0deVET9uwzH
|
Then you can query the data like in the following code sample:
Sample Usage
# Needed imports
from sgqlc.types import Variable, non_null
from sgqlc.operation import Operation
from srgssr_publication_data_api import client, pdp_schema as schema
op = Operation(schema.Query, name='faroItems', variables={'first':non_null(int), 'after':str})
# to restrict fields to just title and cursor (for pagination):
selector = op.faro_items(first=Variable('first'), after=Variable('after'))
selector.edges.title()
selector.cursor()
# if you just want to see the schema, just remove the selector.
print(client.run_query(op, {'first': 100})['data'])
|
Or check the following jupyter example: ...