-
Notifications
You must be signed in to change notification settings - Fork 451
Reference : API
Corentin edited this page May 13, 2020
·
19 revisions
Pizzly comes with an API, which lets you work with your integrations, their configurations and the authentications made.
The API is REST-inspired, meaning that you query it with HTTP methods where GET
= retrieve, PUT
= save, POST
= update and DELETE
= delete. The API accepts and returns JSON objects.
The main endpoints are:
-
/api/:integration
- To retrieve an integration's details (e.g./api/github/
) -
/api/:integration/configurations
- To retrieve a list of configurations for that integration -
/api/integration/configurations/:setupId
- To request a specific configuration -
/api/integration/authentications
- To retrieve a list of authentications for that integration -
/api/integration/authentications/:authId
- To request a specific authentication
After securing your Pizzly's instance, all requests to the API must be authenticated with a secret key. Here's an example in curl on how to make an authenticated request:
curl -X GET /api/github/configurations \
-u "your-secret-key:"
In Node.js, the request requires some extra work:
const fetch = require('fetch-node')
const url = 'http://locahost:8080/api/'
const secretKey = 'secure-secret-key'
const authentication = 'Basic ' + Buffer.from(secretKey + ':').toString('base64')
fetch(url, { headers: { authentication } })
A common use case of the Pizzly's API is to save an integration's configuration on-the-fly.
curl -X GET /api/github
# Should return something like:
#
# {
# "id": "github",
# "object": "integration",
# "...": "..."
# }
#
curl -X POST /api/github/configurations \
-H "Content-Type: application/json" \
-d '{"credentials": { "clientId": "...", "clientSecret": "..." }}'
# Should return something like:
#
# {
# "message": "Configuration registered",
# "configuration": {
# "id": "....",
# "object": "configuration",
# "...": "..."
# }
# }
#
curl -X GET /api/github/configurations/72184458-7751-41fe-8dcc-0251ab2cc578
# Should return something like:
#
# {
# "id": "....",
# "object": "configuration",
# "credentials": { "clientId": "...", "clientSecret": "..." }
# "scopes": ["..."]
# }
#
curl -X PUT /api/github/configurations/72184458-7751-41fe-8dcc-0251ab2cc578 \
-H "Content-Type: application/json" \
-d '{"credentials": { "clientId": "new_id", "clientSecret": "..." }}'
# Should return something like:
#
# { "message": "Configuration updated" }
#
curl -X DELETE /api/github/configurations/72184458-7751-41fe-8dcc-0251ab2cc578 \
# Should return something like:
#
# { "message": "Configuration removed" }
#
curl -X GET /api/github/authentications/
# Should return something like:
#
# {
# "id": "....",
# "object": "authentication",
# "...": "..."
# }
#
curl -X DELETE /api/github/authentications/
# Should return something like:
#
# { "message": "Authentication removed" }
#