@pipedream/servicenow 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,13 +31,14 @@ First, sign into your [ServiceNow Developer Portal](https://developer.servicenow
31
31
  ### Create the OAuth Validator app
32
32
 
33
33
  1. Copy the client ID and secret from the `Pipedream` app you created above.
34
- 2. Name this app `Pipedream OAuth Validator` and add the previously copied client ID and secret.
35
- 3. Set the grant type to **Authorization Code** and the **Token URL** to `oauth_token.do`.
36
- 4. Use the same **Redirect URL** as before.
34
+ 2. Go back to the **System OAuth > Application Registry > New** and select **Connect to an OAuth Provider (simplified)**
35
+ 3. Name this app `Pipedream OAuth Validator` and add the previously copied client ID and secret.
36
+ 4. Set the grant type to **Authorization Code** and the **Token URL** to `oauth_token.do`.
37
+ 5. Use the same **Redirect URL** as before.
37
38
 
38
- 5. Visit [Pipedream's account page](https://pipedream.com/accounts), and click **Click Here to Connect An App**. Search for **ServiceNow** and select it. Enter the client ID, client secret, and your instance name (e.g., `dev98042` from `https://dev98042.service-now.com/`).
39
+ 6. Visit [Pipedream's account page](https://pipedream.com/accounts), and click **Click Here to Connect An App**. Search for **ServiceNow** and select it. Enter the client ID, client secret, and your instance name (e.g., `dev98042` from `https://dev98042.service-now.com/`).
39
40
 
40
- 6. Press **Connect**. A new window will prompt you to login to your ServiceNow instance, authorizing Pipedream's access to the ServiceNow REST API.
41
+ 7. Press **Connect**. A new window will prompt you to login to your ServiceNow instance, authorizing Pipedream's access to the ServiceNow REST API.
41
42
 
42
43
  ## ServiceNow Authorization Reference
43
44
 
@@ -0,0 +1,114 @@
1
+ import servicenow from "../../servicenow.app.mjs";
2
+
3
+ export default {
4
+ key: "servicenow-create-case",
5
+ name: "Create Case",
6
+ description: "Creates a new case record in ServiceNow. [See the docs here](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/integrate/inbound-rest/concept/trouble-ticket-open-api.html#title_trouble-ticket-POST-ticket-tt).",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ props: {
15
+ servicenow,
16
+ name: {
17
+ propDefinition: [
18
+ servicenow,
19
+ "name",
20
+ ],
21
+ },
22
+ description: {
23
+ propDefinition: [
24
+ servicenow,
25
+ "description",
26
+ ],
27
+ },
28
+ severity: {
29
+ propDefinition: [
30
+ servicenow,
31
+ "caseSeverity",
32
+ ],
33
+ },
34
+ status: {
35
+ propDefinition: [
36
+ servicenow,
37
+ "status",
38
+ ],
39
+ },
40
+ channelName: {
41
+ propDefinition: [
42
+ servicenow,
43
+ "channelName",
44
+ ],
45
+ },
46
+ accountId: {
47
+ propDefinition: [
48
+ servicenow,
49
+ "accountId",
50
+ ],
51
+ },
52
+ contactId: {
53
+ propDefinition: [
54
+ servicenow,
55
+ "contactId",
56
+ ],
57
+ },
58
+ workNote: {
59
+ propDefinition: [
60
+ servicenow,
61
+ "workNote",
62
+ ],
63
+ },
64
+ comment: {
65
+ propDefinition: [
66
+ servicenow,
67
+ "comment",
68
+ ],
69
+ },
70
+ },
71
+ async run({ $ }) {
72
+ const {
73
+ name,
74
+ description,
75
+ severity,
76
+ status,
77
+ channelName,
78
+ accountId,
79
+ contactId,
80
+ workNote,
81
+ comment,
82
+ } = this;
83
+
84
+ const channel = this.servicenow.buildChannel(channelName);
85
+
86
+ const notes = this.servicenow.buildNotes({
87
+ workNote,
88
+ comment,
89
+ });
90
+
91
+ const relatedParties = this.servicenow.buildRelatedParties({
92
+ customer: accountId,
93
+ customer_contact: contactId,
94
+ });
95
+
96
+ const response = await this.servicenow.createTroubleTicket({
97
+ $,
98
+ data: {
99
+ ticketType: "Case",
100
+ name,
101
+ description,
102
+ severity,
103
+ status,
104
+ channel,
105
+ notes,
106
+ relatedParties,
107
+ },
108
+ });
109
+
110
+ $.export("$summary", "Successfully created a case.");
111
+
112
+ return response;
113
+ },
114
+ };
@@ -0,0 +1,114 @@
1
+ import servicenow from "../../servicenow.app.mjs";
2
+
3
+ export default {
4
+ key: "servicenow-create-incident",
5
+ name: "Create Incident",
6
+ description: "Creates a new incident record in ServiceNow. [See the docs here](https://www.servicenow.com/docs/bundle/zurich-api-reference/page/integrate/inbound-rest/concept/trouble-ticket-open-api.html#title_trouble-ticket-POST-ticket-tt).",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ props: {
15
+ servicenow,
16
+ name: {
17
+ propDefinition: [
18
+ servicenow,
19
+ "name",
20
+ ],
21
+ },
22
+ description: {
23
+ propDefinition: [
24
+ servicenow,
25
+ "description",
26
+ ],
27
+ },
28
+ severity: {
29
+ propDefinition: [
30
+ servicenow,
31
+ "incidentSeverity",
32
+ ],
33
+ },
34
+ status: {
35
+ propDefinition: [
36
+ servicenow,
37
+ "status",
38
+ ],
39
+ },
40
+ contactMethod: {
41
+ propDefinition: [
42
+ servicenow,
43
+ "contactMethod",
44
+ ],
45
+ },
46
+ companyId: {
47
+ propDefinition: [
48
+ servicenow,
49
+ "companyId",
50
+ ],
51
+ },
52
+ userId: {
53
+ propDefinition: [
54
+ servicenow,
55
+ "userId",
56
+ ],
57
+ },
58
+ workNote: {
59
+ propDefinition: [
60
+ servicenow,
61
+ "workNote",
62
+ ],
63
+ },
64
+ comment: {
65
+ propDefinition: [
66
+ servicenow,
67
+ "comment",
68
+ ],
69
+ },
70
+ },
71
+ async run({ $ }) {
72
+ const {
73
+ name,
74
+ description,
75
+ severity,
76
+ status,
77
+ contactMethod,
78
+ companyId,
79
+ userId,
80
+ workNote,
81
+ comment,
82
+ } = this;
83
+
84
+ const channel = this.servicenow.buildChannel(contactMethod);
85
+
86
+ const relatedParties = this.servicenow.buildRelatedParties({
87
+ customer: companyId,
88
+ customer_contact: userId,
89
+ });
90
+
91
+ const notes = this.servicenow.buildNotes({
92
+ workNote,
93
+ comment,
94
+ });
95
+
96
+ const response = await this.servicenow.createTroubleTicket({
97
+ $,
98
+ data: {
99
+ ticketType: "Incident",
100
+ name,
101
+ description,
102
+ severity,
103
+ status,
104
+ channel,
105
+ notes,
106
+ relatedParties,
107
+ },
108
+ });
109
+
110
+ $.export("$summary", "Successfully created an incident.");
111
+
112
+ return response;
113
+ },
114
+ };
@@ -5,7 +5,12 @@ export default {
5
5
  key: "servicenow-create-table-record",
6
6
  name: "Create Table Record",
7
7
  description: "Inserts one record in the specified table.",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
9
14
  type: "action",
10
15
  props: {
11
16
  servicenow: {
@@ -5,7 +5,12 @@ export default {
5
5
  key: "servicenow-get-table-record-by-sysid",
6
6
  name: "Get Table Record By SysId",
7
7
  description: "Retrieves the record identified by the specified sys_id from the specified table.",
8
- version: "0.3.1",
8
+ version: "0.3.2",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
9
14
  type: "action",
10
15
  props: {
11
16
  servicenow: {
@@ -5,7 +5,12 @@ export default {
5
5
  key: "servicenow-get-table-records",
6
6
  name: "Get Table Records",
7
7
  description: "Retrieves multiple records for the specified table.",
8
- version: "0.3.1",
8
+ version: "0.3.2",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
9
14
  type: "action",
10
15
  props: {
11
16
  servicenow: {
@@ -5,7 +5,12 @@ export default {
5
5
  key: "servicenow-update-table-record",
6
6
  name: "Update Table Record",
7
7
  description: "Updates the specified record with the name-value pairs included in the request body.",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
+ annotations: {
10
+ destructiveHint: true,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
9
14
  type: "action",
10
15
  props: {
11
16
  servicenow: {
@@ -0,0 +1,31 @@
1
+ const DEFAULT_SEVERITY_OPTIONS = [
2
+ {
3
+ label: "Critical",
4
+ value: "1",
5
+ },
6
+ {
7
+ label: "High",
8
+ value: "2",
9
+ },
10
+ {
11
+ label: "Moderate",
12
+ value: "3",
13
+ },
14
+ {
15
+ label: "Low",
16
+ value: "4",
17
+ },
18
+ ];
19
+
20
+ const INCIDENT_SEVERITY_OPTIONS = [
21
+ ...DEFAULT_SEVERITY_OPTIONS,
22
+ {
23
+ label: "Planning",
24
+ value: "5",
25
+ },
26
+ ];
27
+
28
+ export default {
29
+ DEFAULT_SEVERITY_OPTIONS,
30
+ INCIDENT_SEVERITY_OPTIONS,
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/servicenow",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Pipedream servicenow Components",
5
5
  "main": "servicenow.app.mjs",
6
6
  "keywords": [
@@ -13,6 +13,6 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@pipedream/platform": "^3.0.0"
16
+ "@pipedream/platform": "^3.1.0"
17
17
  }
18
18
  }
@@ -1,11 +1,161 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import constants from "./common/constants.mjs";
3
+
4
+ const {
5
+ DEFAULT_SEVERITY_OPTIONS,
6
+ INCIDENT_SEVERITY_OPTIONS,
7
+ } = constants;
8
+
1
9
  export default {
2
10
  type: "app",
3
11
  app: "servicenow",
4
- propDefinitions: {},
12
+ propDefinitions: {
13
+ name: {
14
+ type: "string",
15
+ label: "Name",
16
+ description: "A short description of the ticket issue.",
17
+ optional: true,
18
+ },
19
+ description: {
20
+ type: "string",
21
+ label: "Description",
22
+ description: "A detailed description of the issue.",
23
+ },
24
+ caseSeverity: {
25
+ type: "string",
26
+ label: "Severity",
27
+ description: "The priority/severity of the case.",
28
+ options: DEFAULT_SEVERITY_OPTIONS,
29
+ },
30
+ incidentSeverity: {
31
+ type: "string",
32
+ label: "Severity",
33
+ description: "The priority/severity of the incident.",
34
+ options: INCIDENT_SEVERITY_OPTIONS,
35
+ },
36
+ status: {
37
+ type: "string",
38
+ label: "Status",
39
+ description: "The current status of the ticket.",
40
+ optional: true,
41
+ default: "New",
42
+ },
43
+ channelName: {
44
+ type: "string",
45
+ label: "Channel Name",
46
+ description: "The channel (`contact_type`) that the ticket was created through.",
47
+ optional: true,
48
+ },
49
+ contactMethod: {
50
+ type: "string",
51
+ label: "Contact Method",
52
+ description: "Name of the contact method (`contact_type`) that the ticket was created through.",
53
+ optional: true,
54
+ },
55
+ accountId: {
56
+ type: "string",
57
+ label: "Account ID",
58
+ description: "`Sys_id` of the account related to the case.",
59
+ optional: true,
60
+ },
61
+ contactId: {
62
+ type: "string",
63
+ label: "Contact ID",
64
+ description: "`Sys_id` of the contact related to the case.",
65
+ optional: true,
66
+ },
67
+ companyId: {
68
+ type: "string",
69
+ label: "Company ID",
70
+ description: "`Sys_id` of the company related to the incident.",
71
+ optional: true,
72
+ },
73
+ userId: {
74
+ type: "string",
75
+ label: "User ID",
76
+ description: "`Sys_id` of the user related to the incident.",
77
+ optional: true,
78
+ },
79
+ workNote: {
80
+ type: "string",
81
+ label: "Work Note",
82
+ description: "Internal work note for the ticket.",
83
+ optional: true,
84
+ },
85
+ comment: {
86
+ type: "string",
87
+ label: "Comment",
88
+ description: "Additional comment for the ticket.",
89
+ optional: true,
90
+ },
91
+ },
5
92
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
93
+ baseUrl() {
94
+ const { instance_name: instanceName } = this.$auth;
95
+ return `https://${instanceName}.service-now.com`;
96
+ },
97
+ authHeaders() {
98
+ const { oauth_access_token: oauthAccessToken } = this.$auth;
99
+ return {
100
+ "Authorization": `Bearer ${oauthAccessToken}`,
101
+ "Accept": "application/json",
102
+ "Content-Type": "application/json",
103
+ };
104
+ },
105
+ buildChannel(name) {
106
+ if (!name) {
107
+ return;
108
+ }
109
+ return {
110
+ name,
111
+ };
112
+ },
113
+ buildNotes({
114
+ workNote,
115
+ comment,
116
+ } = {}) {
117
+ const notes = [];
118
+ if (workNote) {
119
+ notes.push({
120
+ "text": workNote,
121
+ "@type": "work_notes",
122
+ });
123
+ }
124
+ if (comment) {
125
+ notes.push({
126
+ "text": comment,
127
+ "@type": "comments",
128
+ });
129
+ }
130
+ return notes.length
131
+ ? notes
132
+ : undefined;
133
+ },
134
+ buildRelatedParties(partyTypeToId = {}) {
135
+ const entries = Object.entries(partyTypeToId)
136
+ .filter(([
137
+ , id,
138
+ ]) => id);
139
+ if (!entries.length) {
140
+ return;
141
+ }
142
+ return entries.map(([
143
+ type,
144
+ id,
145
+ ]) => ({
146
+ id,
147
+ "@referredType": type,
148
+ }));
149
+ },
150
+ async createTroubleTicket({
151
+ $ = this, data,
152
+ } = {}) {
153
+ return axios($, {
154
+ method: "post",
155
+ url: `${this.baseUrl()}/api/sn_ind_tsm_sdwan/ticket/troubleTicket`,
156
+ headers: this.authHeaders(),
157
+ data,
158
+ });
9
159
  },
10
160
  },
11
161
  };