[英]How to access invoke response object variable in following steps of assembly
the assembly of my API Connect API contains two invokes. 我的API的组装Connect API包含两个调用。 The first is calling an internal routing API to get some routing information.
首先是调用内部路由API以获取一些路由信息。 The response of this routing API should not be passed to the second invoke.
该路由API的响应不应传递给第二个调用。
If I do not configure a 'response object variable' in the invoke of the routing API, the original request body is overwritten and the second API gets the result from the routing API as request body. 如果我在路由API的调用中未配置“响应对象变量”,则原始请求主体将被覆盖,第二个API从路由API获得结果作为请求主体。 And if I specify a 'response object variable' in the routing invoke, I can not access the content (json) of this variable in the following steps.
而且,如果我在路由调用中指定了“响应对象变量”,则无法在以下步骤中访问此变量的内容(json)。
How can I solve this issue? 我该如何解决这个问题?
Thx 4 help. 谢谢4帮助。
Rather than relying on reading the request object, you can read from your configured 'response object variable' later on in the flow. 无需依赖于读取请求对象,您可以稍后在流程中从已配置的“响应对象变量”中进行读取。 For instance, if your first invoke has a response object variable set to 'resp1', you can access the JSON payload using '$(resp1.body)' later on in the flow.
例如,如果您的第一次调用将响应对象变量设置为“ resp1”,则可以稍后在流程中使用“ $(resp1.body)”来访问JSON有效负载。 Using this technique will allow you to store the response of each invoke in a separate object, avoiding the overwriting issue.
使用此技术将使您可以将每个调用的响应存储在单独的对象中,从而避免覆盖问题。 These response object variables can be read just like any other context variable in the flow.
这些响应对象变量可以像流中的任何其他上下文变量一样读取。
For more info, check out these links in the Knowledge Center: 有关更多信息,请在知识中心查看以下链接:
Invoke Policy: https://www.ibm.com/support/knowledgecenter/en/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/rapim_ref_ootb_policyinvoke.html 调用策略: https : //www.ibm.com/support/knowledgecenter/zh-CN/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/rapim_ref_ootb_policyinvoke.html
Context Variables: https://www.ibm.com/support/knowledgecenter/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/capim_context_references.html 上下文变量: https : //www.ibm.com/support/knowledgecenter/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/capim_context_references.html
I don't understand this part: 我不明白这部分内容:
[...] "And if I specify a 'response object variable' in the routing invoke, I can not access the content (json) of this variable in the following steps."
[...]并且,如果我在路由调用中指定了“响应对象变量”,则无法在以下步骤中访问此变量的内容(json)。” [...]
[...]
Why can't you access the content of this variable in the following steps? 为什么在以下步骤中无法访问此变量的内容?
... that you received. ...您收到的。 What I'd do is always save a copy of the data received in the invoke to a processed variable instead of the (raw) original request.
我要做的是始终将调用中接收到的数据的副本保存到已处理的变量中,而不是(原始)原始请求中。
In your GatewayScript try something like this: 在您的GatewayScript中,尝试如下操作:
let objRequest = apim.getvariable("request");
let body = null;
Here I recommend you to change the body (if json) to a standard js object 在这里,我建议您将正文(如果json)更改为标准js对象
if(objRequest && objRequest.hasOwnProperty("body")){
try{
body = JSON.parse(objRequest.body);
}catch(e){
body = objRequest.body;
}
}
Remember to stringify the complete object before saving it as global variable . 在将完整对象另存为全局变量之前,请记住将其字符串化 。 Is the only way to store it (because you can only store a string value in this kind of variables)
是存储它的唯一方法(因为您只能在这种变量中存储字符串值)
apim.setvariable("objRequest", JSON.stringify(objRequest));
...that you have saved in global variables you can get it from any other GatewayScript that you want this way: ...您已将其保存在全局变量中,则可以从其他任何想要的GatewayScript中以这种方式获取它 :
let objRequest = JSON.parse(apim.getvariable("objRequest"));
Be careful not to assign an existent name to the apim.setvariable(name, value) because if you use "request" as name instead of "objRequest" (or other), you'll be replacing the original request element , and we don't want that to happen. 注意不要为apim.setvariable(name,value)分配一个存在的名称,因为如果使用“ request”作为名称而不是“ objRequest”(或其他),则将替换原始的request元素 ,而不想那样。
...you can do it with: ...您可以使用:
let statusCode = objRequest.body.status.code;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.