-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPIC-snippets
More file actions
823 lines (732 loc) · 26.4 KB
/
APIC-snippets
File metadata and controls
823 lines (732 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
https://github.com/fdut/apic/tree/435c2200cc8821b3300ec336ea6c74f25ba501d4/gatewayscripts/whoami
https://github.com/Kalumburu/microgateway/tree/8af2307113f84b51028a3992a1dd6d73c595e6c2/test/definitions
https://github.com/jdelagal/hydramigration/blob/9b464c447c2df4cb2673209f593d14d6d5d4521f/migracion/apiconnect/policy/tokenValidation.js
var access_token_request = JSON.stringify(apic.getvariable('request.headers.authorization') ) ;
access_token_request = access_token_request.split(" ")[1].split("\"")[0]
-----
var scopeFound = false;
for (var i = 0; i < reqScopes.length; i++) {
if (apiScopes.indexOf(reqScopes[i]) >= 0) {
scopeFound = true;
break;
}
};
if (!scopeFound) {
throw {
name: "Forbidden",
message: "Insufficient Scope",
errorType: "JWTError",
errorCode: "403"
}
---
swagger: "2.0"
info:
x-ibm-name: "whoami"
title: "whoami"
version: "1.0.0"
schemes:
- "https"
host: "$(catalog.host)"
basePath: "/mockup"
consumes:
- "application/json"
produces:
- "application/json"
securityDefinitions:
clientIdHeader:
type: "apiKey"
in: "header"
name: "X-IBM-Client-Id"
security:
- clientIdHeader: []
x-ibm-configuration:
testable: true
enforced: true
cors:
enabled: true
assembly:
execute:
- gatewayscript:
title: "whoami"
version: "1.0.0"
source: "var out = {\"message\":\"Greeting! Hello World\"};\nout.context=apim.getContext();\n\
session.output.write(JSON.stringify(out));\napim.output(\"application/json\"\
);\n"
phase: "realized"
paths:
/whoami:
get:
responses:
200:
description: "200 OK"
definitions: {}
tags: []
--------
var headerintrospect =
{ "Content-Type": "application/json","Authorization": "bearer "+responseData.access_token} ;
var optionsGetClientID = {
target: target_getClientID,
sslClientProfile : 'webapi-sslcli-mgmt',
method: 'get',
headers: headerintrospect,
contentType: 'application/json',
timeout: 60,
data: {"token": access_token_request}
};
----------
var json = {"tsn": {
"settings":
{"app_name": "TSN", "version": "1.0"},
"occurrences":
["Party", "Music"]
}
};
Object.keys(json.tsn).forEach(function(key){
var item = json.tsn[key];
console.log(item);
});
-----
// Calling external system example.
// This demonstrates use of the DataPower GatewayScript (ECMA) urlopen function.
// Author: Steve Edwards, Escala Ltd.
// Date : 2014-09-30.
// Note : this code is for demonstration purposes only, not production - level.
// For a simple demonstration, this example calls this same service, but with a different URI.
var target = 'http://127.0.0.1/array-string';
var urlopen = require ('urlopen');
var data_to_post = {
"reverseArray": [
1, 2, 3, 4
],
"popArray": [
1, 2, 3, 4
],
"sortArray": [
1, 4, 3, 2
],
"uppercaseString": "Put all this to UpperCase",
"lengthString": "12345678"
};
// The urlopen options, target is defined above:
var options = {
target: target,
method: 'post',
contentType: 'application/json',
timeout: 60,
data: data_to_post
};
// Open connection to target and post data:
urlopen.open (options, function (error, response) {
if (error) {
// an error occurred during request sending or response header parsing
session.output.write ("urlopen connect error: " + JSON.stringify(error));
} else {
// read response data
// Without further processing, response will be:
// {"statusCode":200,"reasonPhrase":"OK","headers":{"X-Backside-Transport":"FAIL FAIL","Content-Type":"application/json","Date":"Fri, 19 Sep 2014 22:50:57 GMT"}}
// get the response status code
var responseStatusCode = response.statusCode;
if (responseStatusCode == 200) {
response.readAsJSON(function(error, responseData) {
if (error) {
// error while reading response
session.output.write("readAsJSON error: " + JSON.stringify(error));
} else {
var urlopenOutput = {"urlopenOutput" : {"statusCode": responseStatusCode,
"urlopenResponse": responseData}
};
session.output.write(urlopenOutput);
}
});
} else {
session.output.write ("urlopen target return statusCode " + responseStatusCode);
}
}
});
/* Sample output:
{
"urlopenOutput": {
"statusCode": 200,
"urlopenResponse": {
"reverseArrayResult": [
4,
3,
2,
1
],
"popArrayResult": 4,
"sortArrayResult": [
1,
2,
3,
4
],
"uppercaseStringResult": "PUT ALL THIS TO UPPERCASE",
"lengthStringResult": 8
}
}
}
*/
=======????
execute:
- gatewayscript:
title: gatewayscript
version: 1.0.0
source: |-
// @ozair @spoon
var out = {"message":"Greeting! Hello World"};
out.whoami = apim.getContext('api.endpoint.address');
session.output.write(JSON.stringify(out));
apim.output("application/json");
---
- gatewayscript:
version: 2.0.0
title: gatewayscript
source: |-
context.message.body.readAsJSON(function (error, response)
{
if (error)
{
return;
}
console.log("response %s", JSON.stringify(response));
context.message.body.write(JSON.stringify(response));
});
======
execute:
- set-variable:
title: set-variable
actions:
- set: message.body
value: '{"message": "Error occurred during search operation."}'
type: string
version: 2.0.0
====
- gatewayscript:
version: 2.0.0
title: gatewayscript
source: |-
context.message.body.readAsJSON(function (error, response)
{
if (error)
{
return;
}
console.log("response %s", JSON.stringify(response));
context.message.body.write(JSON.stringify(response));
});
context.message.statusCode = 200;
======
// output to the system logs, the input parameters passed in the URL query string
console.error('original-url : ', apim.getContext('request.parameters.original-url'));
console.error('app-name : ', apim.getContext('request.parameters.app-name'));
console.error('appid : ', apim.getContext('request.parameters.appid'));
console.error('org : ', apim.getContext('request.parameters.org'));
console.error('orgid : ', apim.getContext('request.parameters.orgid'));
console.error('catalog : ', apim.getContext('request.parameters.catalog'));
console.error('catalogid : ', apim.getContext('request.parameters.catalogid'));
console.error('provider : ', apim.getContext('request.parameters.provider'));
console.error('providerid : ', apim.getContext('request.parameters.providerid'));
"// output to the system logs, the input parameters passed in the URL query string\n
console.error('original-url : ', apim.getContext('request.parameters.original-url'));
console.error('app-name : ', apim.getContext('request.parameters.app-name'));
console.error('appid : ', apim.getContext('request.parameters.appid'));
console.error('org : ', apim.getContext('request.parameters.org'));
console.error('orgid : ',
apim.output('application/json')
apim.readInputAsBuffer(function (error, buffer) {}
apim.output({"httpCode": "401", "httpMessage": "Unauthorized", "moreInformation": "wrong password"}); }
=======
//user-level scope
//set the scope value based on the API assembly set-variable
else if (apim.getContext('request.parameters.component') === 'owner') {
----
/application-level scope
//set the scope value based on the API assembly set-variable
if (apim.getContext('request.parameters.component') === 'application') {
---
"api.endpoint.hostname
==
- switch:
title: "switch"
case:
- condition: "((request.verb==='POST')&&(api.operation.path==='/accounts/balances'))"
execute:
- gatewayscript:
------
- switch:
title: "switch"
case:
- condition: "$(env.path)=='sandbox'"
execute:
- gatewayscript:
---
securityDefinitions:
clientID:
type: apiKey
in: header
name: X-IBM-Client-Id
oauth2:
type: oauth2
x-ibm-oauth-provider: scenario1-oauth
flow: accessCode
authorizationUrl: https://$(catalog.url)/v1/oauth2/authorize
tokenUrl: https://$(catalog.url)/v1/oauth2/token
scopes:
scope1: サンプル・スコープの説明 1
security:
- clientID: []
schemes:
- https
---
basePath: /ro-context
x-ibm-configuration:
assembly:
execute:
- javascript:
source: |-
var name = get('request.headers.x-ro-name');
try {
set(name, 'new value');
throw {name:'ROTextFailedError'};
} catch (e) {
//expect error
if (e.name === 'TypeError') {
message.body = {result:'ok'};
} else {
throw {name:'ROTextFailedError'};
}
}
---
swagger: '2.0'
info:
version: 1.0.0
title: Weather
x-ibm-name: weather
host: $(catalog.host)
basePath: /weather
paths:
/wind:
get:
responses:
'200':
description: 200 OK
/temperature:
get:
responses:
'200':
description: 200 OK
securityDefinitions: {}
---
security: []
schemes:
- http
produces:
- application/json
x-ibm-configuration:
assembly:
execute:
- operation-switch:
title: operation-switch
case:
- operations:
- verb: get
path: /wind
execute:
- set-variable:
title: set-variable
actions:
- set: message.body
value: '{ "wind": "17km/h" }'
- set: message.headers.content-type
value: application/json
- operations:
- verb: get
path: /temperature
execute:
- set-variable:
title: set-variable
actions:
- set: message.body
value: '{ "temperature": "27C" }'
- set: message.headers.content-type
value: application/json
--
x-ibm-configuration:
assembly:
execute:
- invoke:
target-url: "https://localhost:8890/"
tls-profile: "theTlsProfile-bob"
enforced: true
testable: true
phase: realized
cors:
enabled: true
---
x-ibm-configuration:
assembly:
execute:
- set-variable:
title: set-variable
actions:
- set: message.body
value: '{ "id": "$(client.app.id)", "balance": 23501 }'
- set: message.headers.content-type
value: application/json
enforced: true
testable: true
phase: realized
cors:
enabled: true
---
info:
version: 1.0.0
title: basic
x-ibm-name: basic
securityDefinitions:
basic-ldap:
type: basic
description: ''
x-ibm-authentication-url:
url: 'ldap://localhost:1389'
basic-http:
type: basic
description: ''
x-ibm-authentication-url:
url: 'http://localhost:8889/auth'
basePath: /basic
swagger: '2.0'
paths:
/path-2:
get:
responses:
'200':
description: 200 OK
security:
- basic-http: []
/path-1:
get:
responses:
'200':
description: 200 OK
security:
- basic-ldap: []
x-ibm-configuration:
assembly:
execute:
- invoke:
title: invoke
target-url: 'http://localhost:8889/'
schemes:
- 'http'
----
info:
version: 1.0.0
title: ratelimit
x-ibm-name: ratelimit
description: ratelimit test suite
basePath: /ratelimit
swagger: '2.0'
paths:
/ratelimit:
get:
responses:
'200':
description: 200 OK
x-ibm-configuration:
assembly:
execute:
- invoke:
title: invoke
target-url: 'http://localhost:8889/'
schemes:
- http
----
info:
version: 1.0.0
title: cors-disabled
x-ibm-name: cors-disabled
basePath: /cors-disabled
swagger: '2.0'
paths:
/path-cors:
get:
responses:
'200':
description: 200 OK
x-ibm-configuration:
assembly:
execute:
- invoke:
title: invoke
target-url: 'http://localhost:8889/'
cors:
enabled: false
schemes:
- http
-----
paths: # put the paths in alphabetical order
/assembly/identity:
post:
summary: copy input and respond in output
responses:
'200':
description: 200 OK
/assembly/large-payload:
get:
parameters:
- name: size
in: query
description: the size of payload to return
type: integer
responses:
'200':
description: 200 OK
/assembly/policy-not-found:
get:
summary: expect error when policy is not found
responses:
'200':
description: 200 OK
---
x-ibm-configuration:
assembly:
execute:
- invoke:
title: invoke
target-url: 'http://localhost:8889/'
schemes:
- http
---
x-ibm-configuration:
assembly:
execute:
- invoke:
title: invoke
target-url: 'http://localhost:8889/'
schemes:
- https
- http
----
result = myAccountsInfo.accountsData;
if (!result) {
result = {};
}
} catch (e) {
result = e;
}
---
var accountId = apim.getvariable('request.parameters.account-id');
var userId = "";
if (apim.getvariable('request.authorization')) {
userId = apim.getvariable('oauth.resource-owner');
}
-----
=--- assembly:
execute:
- invoke:
target-url: $(TARGET_HOST)$(request.path)$(request.search)
tls-profile: ''
----
- condition: apim.getvariable('HttpMethod') == 'GET'
- condition: apim.getvariable('HttpMethod') == 'POST'
- condition: "request.verb == ('GET')"
- condition: "request.verb == ('POST')"
//Extract general metadata from system variables
var systemDateTime = apim.getvariable('system.datetime');
var apicTxId = apim.getvariable('apic-transaction-id');
var xGlobalTxId = apim.getvariable('request.headers.x-global-transaction-id');
var requestURI = apim.getvariable('request.uri');
//Extract response metadata from system variables
var responseHeaders = apim.getvariable('message.headers');
-----------
x-ibm-configuration:
testable: true
enforced: true
cors:
enabled: true
catalogs:
apic-dev:
properties:
runtime-url: $(TARGET_URL)
sb:
properties:
runtime-url: 'http://localhost:4001'
------
- gatewayscript:
version: 1.0.0
title: GS:FetchValidationConfig
description: This GW Script will create URL to fetch validation config for
all apis
source: |-
var clientId = apim.getvariable('client.app.id');
apim.setvariable('message.headers.x-ibm-client-id', clientId);
apim.setvariable('message.headers.content-type', 'application/json');
//form url for to fetch errorConfig JSON
var orgName = apim.getvariable('api.org.name');
var catalog = apim.getvariable('env.path');
apim.setvariable('apicURLPrefix', 'https://0.0.0.0:9443/'+orgName+'/'+catalog);
var validationConfigURL = apim.getvariable('apicURLPrefix')+'/'+'config/validationconfig';
apim.setvariable('validationConfigURL', validationConfigURL);
//record time in ms just before the invoke policy
apim.setvariable('startTimeMS', (new Date()).getTime());
apim.setvariable('policyName', 'Invoke-ValidationConfig');
- invoke:
version: 1.0.0
title: Invoke-ValidationConfig
timeout: 60
verb: GET
cache-response: protocol
cache-ttl: 900
description: Load all messages and properties in context
target-url: $(validationConfigURL)
output: validationConfig
---
var logString = "type:=response"
+ " | system-datetime:=" + systemDateTime
+ " | total-time-elapsed:=" + totalTimeElapsed;
;
console.log(logString);
-----------
var clientId = apim.getvariable('client.app.id');
apim.setvariable('message.headers.x-ibm-client-id', clientId);
apim.setvariable('message.headers.content-type', 'application/xml');
//form url for to fetch errorConfig JSON
var orgName = apim.getvariable('api.org.name');
var catalog = apim.getvariable('env.path');
apim.setvariable('apicURLPrefix', 'https://0.0.0.0:9443/'+orgName+'/'+catalog);
var soapConfigURL = apim.getvariable('apicURLPrefix')+'/config/soapconfig';
apim.setvariable('soapConfigURL', soapConfigURL);
----------
- gatewayscript:
version: 1.0.0
title: GS-historicUsageAPIURL
source: |2
var uid = uuid();
var userInfoUsageResponse = apim.getvariable('userInfoResponseObj.body');
apim.setvariable('message.headers.User-Agent', 'myo2app/4.1.0');
apim.setvariable('message.headers.content-type','application/json');
apim.setvariable('message.headers.From',userInfoUsageResponse.given_name);
apim.setvariable('message.headers.originator',userInfoUsageResponse.user_id+':'+uid);
apim.setvariable('historicUsageEndpoint','http://lbtest0myo2apptierapigateway.myo2r53.co.uk:8424/sharedata/consumerPAYM/CURRENT/usage/historic/6');
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += "-"
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}
return uuid;
}
//Extract general metadata from system variables
var systemDateTime = apim.getvariable('system.datetime');
var apicTxId = apim.getvariable('apic-transaction-id');
var xGlobalTxId = apim.getvariable('request.headers.x-global-transaction-id');
var requestURI = apim.getvariable('request.uri');
//Extract response metadata from system variables
var responseHeaders = apim.getvariable('message.headers');
general metadata from system variables
var apiStartTimeMS = (new Date()).getTime();\napim.setvariable('apiStartTimeMS',
apiStartTimeMS);
var systemDateTime = apim.getvariable('system.datetime');
var apicTxId = \"\";
if (apim.getvariable('request.headers.apic-transaction-id')){
apicTxId = apim.getvariable('request.headers.apic-transaction-id');}else
{ apicTxId = uuidv4();
}apim.setvariable('apic-transaction-id', apicTxId);
apim.setvariable('message.headers.apic-transaction-id', apicTxId);\n\nvar
xGlobalTxId = apim.getvariable('request.headers.x-global-transaction-id');\n\n//Extract
client metadata from system variables\nvar clientIPAddress = apim.getvariable('request.headers.x-client-ip');\nvar
clientId = apim.getvariable('client.app.id');\nvar clientAppName = apim.getvariable('client.app.name');\nvar
clientAppType = apim.getvariable('client.app.type');\nvar clientOrgName
= apim.getvariable('client.org.name');\n\n//Extract api metadata from system
variables\nvar apiName = apim.getvariable('api.name');\nvar apiVersion =
apim.getvariable('api.version');\nvar providerOrgName = apim.getvariable('api.org.name');\nvar
catalogName = apim.getvariable('env.path');\nvar apiBasePath = apim.getvariable('api.root');\nvar
operationPath = apim.getvariable('api.operation.path');\n\n\n//Extract product
metadata from system variables\n//
var productName = apim.getvariable('product.name');\n//var
productVersion = apim.getvariable('product.version');\nvar planName = apim.getvariable('plan.name');\nvar
planVersion = apim.getvariable('plan.version');\nvar planRateLimit = apim.getvariable('plan.rate-limit');\n\n//Extract
request metadata from system variables\nvar requestMethod = apim.getvariable('request.verb');\nvar
requestURI = apim.getvariable('request.uri');\nvar requestHeaders = apim.getvariable('request.headers');\n\ndelete
requestHeaders['accept-encoding'];\ndelete requestHeaders['x-global-transaction-id'];\ndelete
=---
var optionsintrospection = {
target: target_introspect,
sslClientProfile : 'webapi-sslcli-mgmt',
method: 'post',
headers: headerintrospect,
contentType: 'application/json',
timeout: 60,
data: {"token": access_token_request}
};
var optionsintrospectionKeycloak = {
target: target_introspect_keycloak,
sslClientProfile : 'webapi-sslcli-mgmt',
method: 'post',
headers: headerintrospectKeycloak,
contentType: 'application/x-www-form-urlencoded',
timeout: 60,
data: {}
};
---
========
- gatewayscript:
version: 1.0.0
title: GS-historicUsageAPIURL
source: |2
var uid = uuid();
var userInfoUsageResponse = apim.getvariable('userInfoResponseObj.body');
apim.setvariable('message.headers.User-Agent', 'myo2app/4.1.0');
apim.setvariable('message.headers.content-type','application/json');
apim.setvariable('message.headers.From',userInfoUsageResponse.given_name);
apim.setvariable('message.headers.originator',userInfoUsageResponse.user_id+':'+uid);
apim.setvariable('historicUsageEndpoint','http://lbtest0myo2apptierapigateway.myo2r53.co.uk:8424/sharedata/consumerPAYM/CURRENT/usage/historic/6');
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += "-"
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}
return uuid;
}
//Extract general metadata from system variables
var systemDateTime = apim.getvariable('system.datetime');
var apicTxId = apim.getvariable('apic-transaction-id');
var xGlobalTxId = apim.getvariable('request.headers.x-global-transaction-id');
var requestURI = apim.getvariable('request.uri');
//Extract response metadata from system variables
var responseHeaders = apim.getvariable('message.headers');
general metadata from system variables
var apiStartTimeMS = (new Date()).getTime();\napim.setvariable('apiStartTimeMS',
apiStartTimeMS);
var systemDateTime = apim.getvariable('system.datetime');
var apicTxId = \"\";
if (apim.getvariable('request.headers.apic-transaction-id')){
apicTxId = apim.getvariable('request.headers.apic-transaction-id');}else
{ apicTxId = uuidv4();
}apim.setvariable('apic-transaction-id', apicTxId);
apim.setvariable('message.headers.apic-transaction-id', apicTxId);\n\nvar
xGlobalTxId = apim.getvariable('request.headers.x-global-transaction-id');\n\n//Extract
client metadata from system variables\nvar clientIPAddress = apim.getvariable('request.headers.x-client-ip');\nvar
clientId = apim.getvariable('client.app.id');\nvar clientAppName = apim.getvariable('client.app.name');\nvar
clientAppType = apim.getvariable('client.app.type');\nvar clientOrgName
= apim.getvariable('client.org.name');\n\n//Extract api metadata from system
variables\nvar apiName = apim.getvariable('api.name');\nvar apiVersion =
apim.getvariable('api.version');\nvar providerOrgName = apim.getvariable('api.org.name');\nvar
catalogName = apim.getvariable('env.path');\nvar apiBasePath = apim.getvariable('api.root');\nvar
operationPath = apim.getvariable('api.operation.path');\n\n\n//Extract product
metadata from system variables\n//
var productName = apim.getvariable('product.name');\n//var
productVersion = apim.getvariable('product.version');\nvar planName = apim.getvariable('plan.name');\nvar
planVersion = apim.getvariable('plan.version');\nvar planRateLimit = apim.getvariable('plan.rate-limit');\n\n//Extract
request metadata from system variables\nvar requestMethod = apim.getvariable('request.verb');\nvar
requestURI = apim.getvariable('request.uri');\nvar requestHeaders = apim.getvariable('request.headers');\n\ndelete
requestHeaders['accept-encoding'];\ndelete requestHeaders['x-global-transaction-id'];\ndelete