small script changes and notes
This commit is contained in:
@ -23,18 +23,20 @@ def get_course():
|
||||
status = response["attributes"]["status"]
|
||||
uuid = response["id"]
|
||||
name = response["attributes"]["name"]
|
||||
build_url = response["links"]["builder"]["href"]
|
||||
course_dict = {
|
||||
"id": uuid,
|
||||
"name": name,
|
||||
"status": status,
|
||||
"url": f"https://walmart.northpass.com/app/courses/{uuid}",
|
||||
"build_url": build_url
|
||||
# "url": f"https://walmart.northpass.com/app/courses/{uuid}",
|
||||
}
|
||||
|
||||
# FIX: Up until here, each course gets read to the terminal.
|
||||
# FIX: After this, something is being overwritten.
|
||||
|
||||
cat_id = response["relationships"]["categories"]["data"]
|
||||
# get_cat_name(cat_id, course_dict, courses)
|
||||
get_cat_name(cat_id, course_dict, courses)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
@ -3,78 +3,77 @@ from requests.auth import HTTPBasicAuth
|
||||
import json
|
||||
import os
|
||||
|
||||
# Information
|
||||
#url = "https://northpass.atlassian.net/wiki/rest/api/content/2210463745/child/page"
|
||||
# Information
|
||||
# url = "https://northpass.atlassian.net/wiki/rest/api/content/2210463745/child/page"
|
||||
url = "https://northpass.atlassian.net/wiki/rest/api/content/"
|
||||
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
|
||||
auth = HTTPBasicAuth("nrasmussen@northpass.com","ATATT3xFfGF0QZUomC1s3hvD4Hiqh_usOVFAVLsT1n8lt6gzD7wfL8D8x5ner3SE24JD4E590xoT9PKPIi1Eppanx12q5ALzMHKce-KrcIZRT23BvO8MDXwyvbzAO2R4hALc8ZUTI_8-OM-x9o_tjbCHLxEMFOr6QFDYprwdHGZjAxpviSwXrCQ=218AC438")
|
||||
|
||||
rootdir = "/Users/normrasmussen/Documents/Work/CustomerNotes/"
|
||||
|
||||
rootdir = "/Users/normrasmussen/Documents/Northpass/CustomerNotes/"
|
||||
|
||||
def getCompany():
|
||||
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/Confluence_Notes/SampleNotes/"
|
||||
rootdir = (
|
||||
"/Users/normrasmussen/Documents/Work/CustomerNotes/"
|
||||
)
|
||||
companyName = os.listdir(rootdir)
|
||||
for fileName in companyName:
|
||||
company = fileName[:-3]
|
||||
getPages(company)
|
||||
|
||||
|
||||
def readNewNotes(company):
|
||||
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/Confluence_Notes/SampleNotes/"
|
||||
with open(rootdir+company+".md", "r") as companyfile:
|
||||
rootdir = (
|
||||
"/Users/normrasmussen/Documents/Work/CustomerNotes/"
|
||||
)
|
||||
with open(rootdir + company + ".md", "r") as companyfile:
|
||||
notes = companyfile.read()
|
||||
conversion = markdown.markdown(notes)
|
||||
createNewPage(company, conversion)
|
||||
|
||||
|
||||
def getPages(company):
|
||||
headers = {
|
||||
"Accept": "application/json",
|
||||
}
|
||||
response = requests.request(
|
||||
"GET",
|
||||
url,
|
||||
headers=headers,
|
||||
auth=auth
|
||||
)
|
||||
response = requests.request("GET", url, headers=headers, auth=auth)
|
||||
jsonResponse = response.json()
|
||||
for response in jsonResponse['results']:
|
||||
if response['title'] == company:
|
||||
for response in jsonResponse["results"]:
|
||||
if response["title"] == company:
|
||||
print(f"{company} Found. Updating page....")
|
||||
else:
|
||||
print(f"{company} not found. Create new page...")
|
||||
readNewNotes(company)
|
||||
# readNewNotes(company)
|
||||
|
||||
def createNewPage(company, notes):
|
||||
|
||||
def createNewPage(company, notes):
|
||||
url = "https://northpass.atlassian.net/wiki/rest/api/content/"
|
||||
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
|
||||
headers = {
|
||||
"X-Atlassian-Token": "no-check",
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
payload = json.dumps( {
|
||||
"type":"page",
|
||||
"title": company,
|
||||
"ancestors":[{"id":2210463745}],
|
||||
"space":
|
||||
{"key":"~350535240"},
|
||||
"body":
|
||||
{"storage":
|
||||
{"value": notes,
|
||||
"representation":"storage"}}
|
||||
} )
|
||||
|
||||
response = requests.request(
|
||||
"POST",
|
||||
url,
|
||||
data=payload,
|
||||
headers=headers,
|
||||
auth=auth
|
||||
payload = json.dumps(
|
||||
{
|
||||
"type": "page",
|
||||
"title": company,
|
||||
"ancestors": [{"id": 2210463745}],
|
||||
"space": {"key": "~350535240"},
|
||||
"body": {"storage": {"value": notes, "representation": "storage"}},
|
||||
}
|
||||
)
|
||||
|
||||
response = requests.request("POST", url, data=payload, headers=headers, auth=auth)
|
||||
print("createNewPage function has run")
|
||||
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
|
||||
response = json.dumps(
|
||||
json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
|
||||
)
|
||||
print(response)
|
||||
#jsonResponse = response.json()
|
||||
#print(jsonResponse)
|
||||
# jsonResponse = response.json()
|
||||
# print(jsonResponse)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
createNewPage()
|
||||
#readNewNotes(company="Flink")
|
||||
getCompany()
|
||||
# createNewPage()
|
||||
# readNewNotes(company="Flink")
|
||||
|
||||
1
Scripts/GoogleScripts/Confluence_Test/.clasp.json
Normal file
1
Scripts/GoogleScripts/Confluence_Test/.clasp.json
Normal file
@ -0,0 +1 @@
|
||||
{"scriptId":"1ZUQXaSRZHjVpzJBBFuHdfnLijMJ5jf3swTbonwXJ3nrgeMIh9ffCqe7j","rootDir":"/Users/normrasmussen/Documents/Work/Scripts/GoogleScripts/Confluence_Test"}
|
||||
18
Scripts/GoogleScripts/Confluence_Test/ConfGet.js
Normal file
18
Scripts/GoogleScripts/Confluence_Test/ConfGet.js
Normal file
@ -0,0 +1,18 @@
|
||||
function getPages() {
|
||||
var url = 'https://northpass.atlassian.net/wiki/rest/api/content';
|
||||
const settings = {
|
||||
//async: true,
|
||||
//crossDomain: true,
|
||||
method: 'get',
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"X-Atlassian-Token": "no-check",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Basic bnJhc211c3NlbkBub3J0aHBhc3MuY29tOkFUQVRUM3hGZkdGMFFaVW9tQzFzM2h2RDRIaXFoX3VzT1ZGQVZMc1QxbjhsdDZnekQ3d2ZMOEQ4eDVuZXIzU0UyNEpENEU1OTB4b1Q5UEtQSWkxRXBwYW54MTJxNUFMek1IS2NlLUtyY0laUlQyM0J2TzhNRFh3eXZiekFPMlI0aEFMYzhaVVRJXzgtT00teDlvX3RqYkNITHhFTUZPcjZRRkRZcHJ3ZEhHWmpBeHB2aVN3WHJDUT0yMThBQzQzOA=="
|
||||
},
|
||||
};
|
||||
|
||||
const sendData = UrlFetchApp.fetch(url, settings);
|
||||
var response = sendData.getContentText();
|
||||
Logger.log(response);
|
||||
}
|
||||
7
Scripts/GoogleScripts/Confluence_Test/appsscript.json
Normal file
7
Scripts/GoogleScripts/Confluence_Test/appsscript.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"timeZone": "America/New_York",
|
||||
"dependencies": {
|
||||
},
|
||||
"exceptionLogging": "STACKDRIVER",
|
||||
"runtimeVersion": "V8"
|
||||
}
|
||||
1
Scripts/GoogleScripts/Courtney_Confluence/.clasp.json
Normal file
1
Scripts/GoogleScripts/Courtney_Confluence/.clasp.json
Normal file
@ -0,0 +1 @@
|
||||
{"scriptId":"1TM7cFM57LKm9BoB21N9sCD7j_KDy9z1zrqGDXV8clcwXVwgOKJBpz_0J","rootDir":"/Users/normrasmussen/Documents/Work/Scripts/GoogleScripts/Courtney_Confluence"}
|
||||
40
Scripts/GoogleScripts/Courtney_Confluence/Adv.js
Normal file
40
Scripts/GoogleScripts/Courtney_Confluence/Adv.js
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Test harness to demonstrate getting named styles from the Advanced Docs Service
|
||||
*/
|
||||
function getStylesTestHarness() {
|
||||
// Get the current document
|
||||
var doc = DocumentApp.getActiveDocument()
|
||||
|
||||
// https://developers.google.com/apps-script/reference/document/paragraph-heading
|
||||
var namedStyleType = DocumentApp.ParagraphHeading.HEADING2;
|
||||
getStyles_(doc.getId(), namedStyleType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get named styles from the Advanced Docs Service
|
||||
* Assumes that heading text is unique, which it should be with date stamp
|
||||
* @param {string} documentId
|
||||
* @param {string} styleType https://developers.google.com/apps-script/reference/document/paragraph-heading
|
||||
* @private
|
||||
*/
|
||||
function getStyles_(documentId, styleType) {
|
||||
|
||||
var namedStyleArr;
|
||||
var namedStyleObj;
|
||||
var appsScriptNamedStyle;
|
||||
|
||||
// Get the corresponding document from the Advanced Docs Service
|
||||
var document = Docs.Documents.get(documentId);
|
||||
var namedStyleArr = document.namedStyles.styles;
|
||||
|
||||
for (var i=namedStyleArr.length;i--;) {
|
||||
namedStyleObj = namedStyleArr[i];
|
||||
// convert from Advanced Docs Service style names which have separating underscores
|
||||
appsScriptNamedStyle = namedStyleObj.namedStyleType.split('_').join('');
|
||||
if (appsScriptNamedStyle == styleType) {
|
||||
console.log('namedStyleType '+namedStyleObj.namedStyleType);
|
||||
console.log('textStyle '+JSON.stringify(namedStyleObj.textStyle));
|
||||
console.log('paragraphStyle '+JSON.stringify(namedStyleObj.paragraphStyle));
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Scripts/GoogleScripts/Courtney_Confluence/Confluence.js
Normal file
29
Scripts/GoogleScripts/Courtney_Confluence/Confluence.js
Normal file
@ -0,0 +1,29 @@
|
||||
function uploadToConfluence() {
|
||||
var doc = DocumentApp.getActiveDocument();
|
||||
var body = doc.getText();
|
||||
var company = doc.getName();
|
||||
//Logger.log(typeof body);
|
||||
//Logger.log(typeof company)
|
||||
|
||||
var url = 'https://northpass.atlassian.net/wiki/rest/api/content';
|
||||
const payload = JSON.stringify({
|
||||
"type": "page",
|
||||
"title": company,
|
||||
"status": "current",
|
||||
"ancestors": [{"id": 2210463745}],
|
||||
"space": {"key": "~350535240"},
|
||||
"body": {"storage": {"value": body, "representation": "storage"}},
|
||||
});
|
||||
const settings = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"X-Atlassian-Token": "no-check",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Basic bnJhc211c3NlbkBub3J0aHBhc3MuY29tOkFUQVRUM3hGZkdGMFFaVW9tQzFzM2h2RDRIaXFoX3VzT1ZGQVZMc1QxbjhsdDZnekQ3d2ZMOEQ4eDVuZXIzU0UyNEpENEU1OTB4b1Q5UEtQSWkxRXBwYW54MTJxNUFMek1IS2NlLUtyY0laUlQyM0J2TzhNRFh3eXZiekFPMlI0aEFMYzhaVVRJXzgtT00teDlvX3RqYkNITHhFTUZPcjZRRkRZcHJ3ZEhHWmpBeHB2aVN3WHJDUT0yMThBQzQzOA=="},
|
||||
payload: payload
|
||||
};
|
||||
const sendData = UrlFetchApp.fetch(url, settings);
|
||||
var response = sendData.getContentText();
|
||||
Logger.log(response);
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
{
|
||||
"timeZone": "America/New_York",
|
||||
"dependencies": {
|
||||
},
|
||||
"exceptionLogging": "STACKDRIVER",
|
||||
"runtimeVersion": "V8"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
class credential:
|
||||
def __init__(self, hostname, username, password, apikey):
|
||||
self.hostname = hostname
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.apikey = apikey
|
||||
87
Scripts/csvTest.js
Normal file
87
Scripts/csvTest.js
Normal file
@ -0,0 +1,87 @@
|
||||
const fs = require("fs");
|
||||
const { parse } = require("csv-parse");
|
||||
const axios = require('axios');
|
||||
var array = [];
|
||||
const apiKey = 'RfmxChNLLodO6M0Z88BwG9Xyu'
|
||||
|
||||
function wait(ms) {
|
||||
return new Promise(r => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
function getUserProps(xApiKey, person) {
|
||||
|
||||
axios({
|
||||
method: 'get',
|
||||
url: 'https://api.northpass.com/v2/properties/people/' + person,
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'x-api-key': xApiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
info = '"' + res.data.data.attributes.properties.account_name + '"' + ';' + '"' + res.data.data.attributes.properties.company + '"' + '\n'
|
||||
fs.appendFile('harriUserProps.csv', info, function(err) {
|
||||
if (err) throw err;
|
||||
console.log('Saved!');
|
||||
return 'saved'
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
function fetchPeople(xApiKey, users, num) {
|
||||
let index = num;
|
||||
axios({
|
||||
method: 'get',
|
||||
url: 'https://api.northpass.com/v2/people?filter[' + users[index][0] + ']=' + encodeURIComponent(users[index][1]),
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'x-api-key': xApiKey,
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
if (index < users.length - 1) {
|
||||
console.log(index)
|
||||
console.log(users[index][0], users[index][1], res.data.data[0].id)
|
||||
getUserProps(xApiKey, res.data.data[0].id)
|
||||
index++;
|
||||
wait(300)
|
||||
fetchPeople(xApiKey, users, index)
|
||||
wait(300)
|
||||
} else {
|
||||
getUserProps(xApiKey, res.data.data[0].id)
|
||||
console.log("complete")
|
||||
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
function csvReader(someArray, filePath) {
|
||||
fs.createReadStream(filePath)
|
||||
.pipe(parse({
|
||||
delimiter: ',',
|
||||
columns: true
|
||||
}))
|
||||
.on("data", function(row) {
|
||||
if (row['Email'] == '') {
|
||||
someArray.push(['sso_uid', row['SSO UID']])
|
||||
} else {
|
||||
someArray.push(['email', row['Email']])
|
||||
}
|
||||
})
|
||||
.on("error", function(error) {
|
||||
console.log(error.message);
|
||||
})
|
||||
.on("end", async function() {
|
||||
console.log("finished");
|
||||
fetchPeople(apiKey, someArray, 0)
|
||||
})
|
||||
}
|
||||
|
||||
csvReader(array, "Untitled spreadsheet - harri-academy-people.csv")
|
||||
@ -1,65 +0,0 @@
|
||||
import adbase
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
|
||||
|
||||
class birdnet(adbase.ADBase):
|
||||
def initialize(self):
|
||||
self.hassapi = self.get_plugin_api("HASS")
|
||||
self.adapi = self.get_ad_api()
|
||||
self.mqttapi = self.get_plugin_api("MQTT")
|
||||
self.birdnet_mqtt = "birdnet"
|
||||
self.mqttapi.listen_event(
|
||||
self.birdnet_message, "MQTT_MESSAGE", topic=self.birdnet_mqtt
|
||||
)
|
||||
|
||||
def birdnet_message(self, event_name, data, kwargs):
|
||||
pre_split = data["payload"]
|
||||
|
||||
common_name = pre_split.split(",")[0].strip()
|
||||
science_name = pre_split.split(",")[1].strip()
|
||||
date_seen = pre_split.split(",")[2].strip
|
||||
time_seen = pre_split.split(",")[3].strip()
|
||||
confidence = pre_split.split(",")[5].strip()
|
||||
|
||||
# print(f"A {common_name} was seen on {date_seen} at {time_seen}. Confidence is {confidence}.")
|
||||
|
||||
self.mqttapi.mqtt_publish("birdnet/sensors/common_name", common_name)
|
||||
self.mqttapi.mqtt_publish("birdnet/sensors/science_name", science_name)
|
||||
self.mqttapi.mqtt_publish("birdnet/sensors/time_seen", time_seen)
|
||||
self.mqttapi.mqtt_publish("birdnet/sensors/date_seen", date_seen)
|
||||
self.mqttapi.mqtt_publish("birdnet/sensors/confidence", confidence)
|
||||
|
||||
url = f"https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles={science_name}"
|
||||
response = requests.get(url)
|
||||
response = response.json()
|
||||
|
||||
for value in response["query"]["pages"]:
|
||||
wiki_desc = response["query"]["pages"][value]["extract"]
|
||||
self.hassapi.set_state(
|
||||
"sensor.birdnet_wiki", state="on", attributes={"description": wiki_desc}
|
||||
)
|
||||
|
||||
headers = {"User-Agent": "Python_Flickr/1.0"}
|
||||
flickr_api = "2b550e7db4a944843a46e57c263582e3"
|
||||
flickr_url = f"https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key={flickr_api}&text={common_name} bird&sort=relevance&per_page=5&media=photos&format=json&nojsoncallback=1"
|
||||
flickr_resp = requests.get(url=flickr_url, headers=headers)
|
||||
data = flickr_resp.json()["photos"]["photo"][0]
|
||||
print(data)
|
||||
|
||||
image_url = (
|
||||
"https://farm"
|
||||
+ str(data["farm"])
|
||||
+ ".static.flickr.com/"
|
||||
+ str(data["server"])
|
||||
+ "/"
|
||||
+ str(data["id"])
|
||||
+ "_"
|
||||
+ str(data["secret"])
|
||||
+ "_n.jpg"
|
||||
)
|
||||
|
||||
self.hassapi.set_state(
|
||||
"sensor.birdpic_test", state="on", attributes={"image": image_url}
|
||||
)
|
||||
165
Scripts/hubspotTicketSetup.js
Normal file
165
Scripts/hubspotTicketSetup.js
Normal file
@ -0,0 +1,165 @@
|
||||
const fetch = require("node-fetch");
|
||||
const api_key = "Bearer pat-na1-446d4baf-0d69-49ff-91ed-2419c1ef76ba";
|
||||
|
||||
|
||||
let ticketBaseURL = 'https://api.hubapi.com/crm/v3/objects/tickets/';
|
||||
let ticketURLParams = '?associations=company,contact,conversations&properties=estimated_hours,impact_scope,ticket_priority,school_url,sandbox_url,issue_type,product_area,specific_product_area,hubspot_owner_id,subject,content,package_level,description'
|
||||
let contactBaseURL = 'https://api.hubapi.com/crm/v3/objects/contacts/';
|
||||
let reporterBaseURL = 'https://api.hubapi.com/crm/v3/owners/';
|
||||
let contactURLParams = '?associations=company&properties=company,email,firstname,lastname';
|
||||
let ticketID = ;
|
||||
let ticket = {
|
||||
"fields": {
|
||||
"project": {
|
||||
"key": "SET"
|
||||
}
|
||||
}
|
||||
};
|
||||
let options = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: api_key,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function wait(ms) {
|
||||
return new Promise(r => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
async function getTicketInfo(ticketID) {
|
||||
const ticketResp = await fetch(ticketBaseURL + ticketID + ticketURLParams, options);
|
||||
const ticketData = await ticketResp.json();
|
||||
const reporterResp = await fetch(reporterBaseURL + ticketData.properties.hubspot_owner_id, options);
|
||||
const reporterData = await reporterResp.json();
|
||||
const contactResp = await fetch(contactBaseURL + ticketData.associations.contacts.results[0].id + contactURLParams, options);
|
||||
const contactData = await contactResp.json();
|
||||
const jiraResp = await fetch('https://northpass.atlassian.net/rest/api/3/user/search?query=' + reporterData.email, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Basic Y2JlbmNpdmVuZ2FAbm9ydGhwYXNzLmNvbTpRcm1nSjVDbG00dUdvQXVWTnp5OTlFMzM=`,
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
|
||||
});
|
||||
const jiraData = await jiraResp.json();
|
||||
|
||||
try {
|
||||
if (ticketData) {
|
||||
console.log(ticketData)
|
||||
console.log(ticketData.associations.companies.results);
|
||||
console.log(contactData)
|
||||
console.log(reporterData)
|
||||
if (ticketData.properties.hasOwnProperty('issue_type')) {
|
||||
ticket.fields.issuetype = { "name": ticketData.properties.issue_type };
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('impact_scope') && ticketData.properties.issue_type == 'Bug') {
|
||||
ticket.fields.customfield_10170 = { "value": ticketData.properties.impact_scope }
|
||||
}
|
||||
|
||||
if (ticketData.properties.hasOwnProperty('ticket_priority')) {
|
||||
ticket.fields.priority = { "name": ticketData.properties.ticket_priority }
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('school_url')) {
|
||||
if (ticketData.properties.school_url.indexOf("https") == 0) {
|
||||
ticket.fields.customfield_10171 = ticketData.properties.school_url
|
||||
} else {
|
||||
ticket.fields.customfield_10171 = "https://" + ticketData.properties.school_url
|
||||
}
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('sandbox_url') && ticketData.properties.issue_type == 'Change') {
|
||||
if (ticketData.properties.school_url.indexOf("https") == 0) {
|
||||
ticket.fields.customfield_10172 = ticketData.properties.sandbox_url
|
||||
} else {
|
||||
ticket.fields.customfield_10172 = "https://" + ticketData.properties.sandbox_url
|
||||
}
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('product_area') && (ticketData.properties.issue_type !== 'Information' && ticketData.properties.issue_type !== 'Demo')) {
|
||||
ticket.fields.customfield_10168 = { "value": ticketData.properties.product_area }
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('estimated_hours')) {
|
||||
if (ticketData.properties.estimated_hours) {
|
||||
ticket.fields.timetracking = {
|
||||
"originalEstimate": ticketData.properties.estimated_hours + 'h',
|
||||
"remainingEstimate": ticketData.properties.estimated_hours + 'h'
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('specific_product_area') && (ticketData.properties.issue_type !== 'Information' && ticketData.properties.issue_type !== 'Demo')) {
|
||||
ticket.fields.customfield_10169 = { "value": ticketData.properties.specific_product_area }
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('subject')) {
|
||||
ticket.fields.summary = ticketData.properties.subject
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('content') && ticketData.properties.content !== null) {
|
||||
ticket.fields.description = {
|
||||
"version": 1,
|
||||
"type": "doc",
|
||||
"content": [{
|
||||
"type": "paragraph",
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": ticketData.properties.content
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('package_level')) {
|
||||
ticket.fields.customfield_10156 = { "value": ticketData.properties.package_level }
|
||||
}
|
||||
if (ticketData.associations.companies.results[0].hasOwnProperty('id')) {
|
||||
ticket.fields.customfield_10173 = ticketData.associations.companies.results[0].id
|
||||
}
|
||||
if (ticketData.properties.hasOwnProperty('due_date') && ticketData.properties.issue_type == 'Demo') {
|
||||
ticket.fields.duedate = ticketData.properties.due_date
|
||||
}
|
||||
if (ticketData.associations.hasOwnProperty('conversations')) {
|
||||
if (ticketData.associations.conversations.results[0].hasOwnProperty('id')) {
|
||||
ticket.fields.customfield_10176 = ticketData.associations.conversations.results[0].id
|
||||
}
|
||||
}
|
||||
if (ticketID) {
|
||||
ticket.fields.customfield_10174 = ticketID.toString()
|
||||
}
|
||||
if (contactData.properties.hasOwnProperty('company')) {
|
||||
ticket.fields.customfield_10028 = [contactData.properties.company.replace(/\s/g, '')]
|
||||
}
|
||||
// No reason to use this yet. Will think about about keeping it or removing
|
||||
// if (contactData.properties.hasOwnProperty('email')) {
|
||||
// ticket.fields.customerEmail = contactData.properties.email
|
||||
// }
|
||||
if (jiraData[0].hasOwnProperty('accountId')) {
|
||||
ticket.fields.reporter = { "accountId": jiraData[0].accountId }
|
||||
}
|
||||
|
||||
console.log(ticket)
|
||||
|
||||
let bodyData = JSON.stringify(ticket)
|
||||
|
||||
fetch('https://northpass.atlassian.net/rest/api/3/issue', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Basic Y2JlbmNpdmVuZ2FAbm9ydGhwYXNzLmNvbTpRcm1nSjVDbG00dUdvQXVWTnp5OTlFMzM=`,
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: bodyData
|
||||
})
|
||||
.then(response => {
|
||||
console.log(
|
||||
`Response: ${response.status} ${response.statusText}`
|
||||
);
|
||||
return response.text();
|
||||
})
|
||||
.then(text => console.log(text))
|
||||
.catch(err => console.error(err));
|
||||
return ticket
|
||||
} else {
|
||||
console.log("complete");
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
};
|
||||
};
|
||||
|
||||
getTicketInfo(ticketID);
|
||||
Reference in New Issue
Block a user