Skip to content

Instantly share code, notes, and snippets.

@stmcallister
stmcallister / lowercaseJsonNodeNames.java
Last active December 21, 2016 23:05
I have a program that needed to consume a second API where the field names in the JSON response could be capitalized, or might not. We're using JsonNode to parse the responses, and this is a solution I came up with. I'm posting it here as it may help others - or could be improved with feedback.
private static JsonNode lowercaseNodeNames(JsonNode node) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode loweredNode = mapper.createObjectNode();
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
String currentName = fieldNames.next();
JsonNode currentValue = null;
if (node.get(currentName).isObject()) {
// checking for nestedNode in currentNode
@stmcallister
stmcallister / createSmartsheetUpdateRequest.java
Last active May 9, 2017 21:16
Create Smartsheet UpdateRequest with Java SDK
// This is a sample for creating an UpdateRequest in Smartsheet
private static void createUpdateRequest() throws SmartsheetException {
Token token = new Token();
// Generate third party access token in Smartsheet.
// To learn how: https://smartsheet-platform.github.io/api-docs/?java#direct-api-access
token.setAccessToken("third-party-access-token");
// Use the Smartsheet Builder to create a Smartsheet object
Smartsheet smartsheet = new SmartsheetBuilder().setAccessToken(token.getAccessToken()).build();
@stmcallister
stmcallister / smartsheet_api_error_parse.py
Last active October 28, 2022 18:56
Accessing Smartsheet ApiError object in Python
#!/usr/bin/env python
import smartsheet
import os
import json
ss_client = smartsheet.Smartsheet(os.environ['SMARTSHEET_ACCESS_TOKEN'])
ss_client.errors_as_exceptions()
sheet_ID = xxxxxxxxxxxxxxxx
@stmcallister
stmcallister / smartsheet-add-row-with-predecessor.py
Last active September 7, 2018 18:27
Adding a row that contains a cell with a PREDECESSOR_LIST type
#!/usr/bin/env python
import smartsheet
import os
import json
import datetime
ss_client = smartsheet.Smartsheet(os.environ['SMARTSHEET_ACCESS_TOKEN'])
ss_client.errors_as_exceptions()
sheet_ID = 2089332342318980
@stmcallister
stmcallister / smartsheet-get-sheets-from-workspace.py
Created November 16, 2018 01:49
List sheets from a workspace in Smartsheet and gather the rowIds and primaryColumnId in the sheet
#!/usr/bin/env python
import smartsheet
import os
import json
import logging
logging.basicConfig(filename='mylog.log', level=logging.DEBUG)
ss_client = smartsheet.Smartsheet(os.environ['SMARTSHEET_ACCESS_TOKEN'])
ss_client.errors_as_exceptions()
@stmcallister
stmcallister / pagerduty-pdpyras-trigger-event-get-incident.py
Last active July 23, 2020 18:06
Python script for creating an Event and then retrieving the Incident in PagerDuty
import pdpyras
import time
from pdpyras import APISession
# API Token and Session for REST API
api_token = 'your_api_token'
rest_session = APISession(api_token)
# Routing Key and Session for Events API
routing_key = 'your_routing_key'
@stmcallister
stmcallister / pd-pdpyras-create-integration.py
Last active August 6, 2020 23:23
Python script for creating an AppDynamics integration for a PagerDuty service
from pdpyras import APISession
import os
# api_token: an API key for the PagerDuty account with read/write access
# - To create API key see https://support.pagerduty.com/docs/generating-api-keys
api_token = os.getenv('PD_API_KEY')
session = APISession(api_token)
# Sample to create an AppDynamics Integration
@stmcallister
stmcallister / ngrok-pd-hook.go
Created June 9, 2023 23:43
ngrok-pagerduty-webhook-verification
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"