This thread is important so I am trying to provide a simple swagger that will point everyone in the correct directions and also will show why we are stumbling so much on this issue with a very easy solution. It cannot be accessed directly inside the gatewayscript (with context.get() or apim.getvaraible()). You need to access it first with set-variable via the $(var) notation. There you can assign it to any other existent/new context variable and use the latter one in the gollowing gatewayscripts.
swagger: '2.0'
info:
title: test
x-ibm-name: test
version: 1.0
basePath: /test
x-ibm-configuration:
cors:
enabled: true
gateway: datapower-api-gateway
type: rest
phase: realized
enforced: true
testable: true
assembly:
execute:
- set-variable:
version: 2.0.0
actions:
- set: t.one
value: Bumblebee
type: string
- set: a
value: $(avenger)
type: string
- gatewayscript:
version: 2.0.0
title: gatewayscript
source: context.set("t.two", "Optimus Prime");
- set-variable:
version: 2.0.0
actions:
- set: p
value: $(pokemon)
type: string
- set: a
value: $(avenger)
type: string
- gatewayscript:
version: 2.0.0
title: gatewayscript
source: |-
let body = {
"pokemon_1": context.get("p"),
"pokemon_2": context.get("pokemon"),
"transformer_1": context.get("t.one"),
"transformer_2": context.get("t.two"),
"avenger_1": context.get("a"),
"avenger_2": context.get("avenger")
}
context.message.header.set('Content-Type', 'application/json');
context.message.body.write(body);
properties:
avenger:
value: Iron Man
encoded: false
application-authentication: {}
activity-log:
enabled: true
success-content: activity
error-content: payload
paths:
/:
get:
responses:
'200':
description: success
schema:
type: string
securityDefinitions: {}
security: []
schemes:
- https
produces:
- application/json
consumes:
- application/json
It will produce the following output:
{
"pokemon_1": "Pikachu",
"pokemon_2": null,
"transformer_1": "Bumblebee",
"transformer_2": "Optimus Prime",
"avenger_1": "Iron Man",
"avenger_2": "Iron Man"
}
Of course, you´ll need to have the `pokemon` property set up in the Catalog (web API Manager) before publishing the API:
The fact that "pokemon_2" is failing and the fact that you create the catalog property after publishing the API, are the common reasons for users to fail on this feature.
Kind regards,
------------------------------
Adrian Ruben Dogar
------------------------------
Original Message:
Sent: Wed March 09, 2022 02:10 AM
From: Anurag Gupta
Subject: Cannot able to Define Catalog specific property values in API Properties
I want to put domain of target url in Catalog define properties as it is volatile n changes frequently so I am try to use the property in API to invoke endpoints but these property isn't working out.
I followed these for ref. -
Defining Catalog specific property values
Setting API properties
------------------------------
Anurag Gupta
------------------------------