Skip to content

Instantly share code, notes, and snippets.

@younishd
Created July 22, 2019 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save younishd/e69f87e882ed20703d88ec0bf65fb1e7 to your computer and use it in GitHub Desktop.
Save younishd/e69f87e882ed20703d88ec0bf65fb1e7 to your computer and use it in GitHub Desktop.
Papershift <> Personio
##
## Author: Younis Bensalah
##
from requests import get, post
import json
PAPERSHIFT_API_TOKEN = 'XXXXXXXX'
PERSONIO_CLIENT_ID = 'XXXXXXXX'
PERSONIO_CLIENT_SECRET = 'XXXXXXXX'
PAPERSHIFT_API_ENDPOINT = 'https://app.papershift.com/public_api/v1'
PERSONIO_API_ENDPOINT = 'https://api.personio.de/v1'
# personio auth
response = post(PERSONIO_API_ENDPOINT + '/auth', params={
"client_id": PERSONIO_CLIENT_ID,
"client_secret": PERSONIO_CLIENT_SECRET
})
if response.status_code != 200:
return {"response": response.text}
personio_token = json.loads(response.text)['data']['token']
# get user from papershift
response = get(PAPERSHIFT_API_ENDPOINT + '/users', params={
"api_token": PAPERSHIFT_API_TOKEN,
"id": input_data['user_id']
})
if response.status_code != 200:
return {"response": response.text}
user = json.loads(response.text)
# get absence from papershift
response = get(PAPERSHIFT_API_ENDPOINT + '/absences', params={
"api_token": PAPERSHIFT_API_TOKEN,
"id": input_data['absence_id']
})
if response.status_code != 200:
return {"response": response.text}
absence = json.loads(response.text)
# post time-off to personio
response = post(PERSONIO_API_ENDPOINT + '/company/time-offs', json={
"employee_id": user['external_id'],
"time_off_type_id": absence['absence_type_external_id'],
"start_date": absence['starts_at'][0:10],
"end_date": absence['ends_at'][0:10],
"half_day_start": absence['full_day'],
"half_day_end": absence['full_day']
}, headers={
"Authorization": 'Bearer ' + personio_token
})
return {"response": response.text}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment