Skip to content

Instantly share code, notes, and snippets.

@inkredabull
Last active January 28, 2019 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inkredabull/9fc43b2438c6b8c610b0f105a04f5656 to your computer and use it in GitHub Desktop.
Save inkredabull/9fc43b2438c6b8c610b0f105a04f5656 to your computer and use it in GitHub Desktop.
Batch update for PeopleGoal

TL;DR Script for updating PeopleGoal Feedback Questions per User

Details

Discovered PeopleGoal recently.

I like codifying peoples' job responsibilities via the Feedback Question but for 33 reports in my org, neither I nor my managers can be bothered to key-in each via the UI.

Am told by PeopleGoal customer support their public API might be available later in 2019.

The workaround: figure out how to update via CLI.

  1. got working with Postman
  2. copy-pasted Python code
  3. created responsiblities.txt locally
  4. added looping to go through users and add responsbilities programmatically

Add feedback questions

Usage

$ SESSION=<SESSION_ID_FROM_COOKIES> python peoplegoal_updater.py <USER_ID> <QUESTION_ID>

Code

# YMMV; provided as-is, no warranty
import sys
import urllib
import requests
import os

user_id = sys.argv[1]
starting_question_id = sys.argv[2]
next_question_id = int(starting_question_id) + 1
session=os.environ['SESSION']

print "***************"

lines = tuple(open("responsibilites.txt", 'r'))
for line in lines:
    responsibility = line.rstrip()

    url = "https://decorist.peoplegoal.com/feedback_questions/" + user_id + "/new_user_feedback_question"
    headers = {
        'Cookie': "_peoplegoal_v2_session_store=" + session + ";"
    }

    # Creates a new question, but doesn't return ID of question 
    print "Question ID: " + str(next_question_id)
    response = requests.request("GET", url, headers=headers)
    print "HTTP Code (New Question): " + str(response.status_code)

    url = "https://decorist.peoplegoal.com/feedback_questions/" + str(next_question_id)

    payload = "{\"feedback_question\": { \"question_text\": \"" + responsibility + "\"} }"
    headers = {
        'Cookie': "_peoplegoal_v2_session_store=" + session + ";",
        'Content-Type': "application/json"
    }

    # Update the question
    response = requests.request("PUT", url, data=payload, headers=headers)

    print "Responsiblity: '" + responsibility + "'"
    print "HTTP Code (Question Updated): " + str(response.status_code)

    next_question_id += 1
    print "***************"

Delete feedback question

Usage

$ SESSION=<SESSION_ID_FROM_COOKIES> python cleanup.py <QUESTION_ID>

Code

# YMMV; provided as-is, no warranty
import sys
import requests
import os

question_id = sys.argv[1]
session=os.environ['SESSION']

url = "https://decorist.peoplegoal.com/feedback_questions/" + question_id
payload = "_method=delete"
headers = {
    'Cookie': "_peoplegoal_v2_session_store=" + session + ";",
    'Content-Type': "application/x-www-form-urlencoded"
}

response = requests.request("POST", url, data=payload, headers=headers)
print response.status_code # getting 500 but question is deleted...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment