Closed akpuvvada closed 4 years ago
What type is ‘CityCode_Input’ set to on the flow? Also if you log ‘CityCode_Input’ what does it print?
It is defined as Object
"metadata": {
"input": [
{
"name": "CityCode_Input",
"type": "object"
},
Please help!
if you log ‘CityCode_Input’ what does it print? Also, do you get an error? Do you have the logs for this?
Log activity is not working in AWS. I am checking on that on https://github.com/project-flogo/aws-contrib/issues/10.
However, from what I understand it is coming as String. Like -> {"body":"{\"zipcode\":\"07604\"}"}
Once the logging activity is fixed, try logging it. Also, have you tried the following?
"id": "rest_3",
"name": "AccuWeather_GET_RESTInvoke",
"description": "Invokes a REST Service",
"activity": {
"ref": "#rest",
"input": {
"pathParams": {
"mapping": {
"zipC": "=$flow.CityCode_Input.body.zipcode"
}
},
Ok, I got the log to work now, thanks to Samip.
I am getting null for that.
Below is the complete log if I log '$.event' of which I am mapping 'data' to 'CityCode_Input' as mentioned in issue description.
Hope these details help. Let me know if you need more details.
{
"body": "{\"zipcode\":\"07604\"}",
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Cache-Control": "no-cache",
"Content-Type": "application/json",
"Host": "ob2nu3js53.execute-api.us-east-2.amazonaws.com",
"Postman-Token": "98fba720-0650-412b-9e66-0780cea47fe5",
"User-Agent": "PostmanRuntime/7.20.1",
"X-Amzn-Trace-Id": "Root=1-5de6c75a-e499295e165fdd973afafa77",
"X-Forwarded-For": "139.180.244.174",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"httpMethod": "POST",
"isBase64Encoded": false,
"multiValueHeaders": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Cache-Control": [
"no-cache"
],
"Content-Type": [
"application/json"
],
"Host": [
"ob2nu3js53.execute-api.us-east-2.amazonaws.com"
],
"Postman-Token": [
"98fba720-0650-412b-9e66-0780cea47fe5"
],
"User-Agent": [
"PostmanRuntime/7.20.1"
],
"X-Amzn-Trace-Id": [
"Root=1-5de6c75a-e499295e165fdd973afafa77"
],
"X-Forwarded-For": [
"139.180.244.174"
],
"X-Forwarded-Port": [
"443"
],
"X-Forwarded-Proto": [
"https"
]
},
"multiValueQueryStringParameters": null,
"path": "/AWS_Lambda_REST_POC_INI2",
"pathParameters": null,
"queryStringParameters": null,
"requestContext": {
"accountId": "034413604559",
"apiId": "ob2nu3js53",
"domainName": "ob2nu3js53.execute-api.us-east-2.amazonaws.com",
"domainPrefix": "ob2nu3js53",
"extendedRequestId": "EJQWOFSZiYcFcZA=",
"httpMethod": "POST",
"identity": {
"accessKey": null,
"accountId": null,
"caller": null,
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityId": null,
"cognitoIdentityPoolId": null,
"principalOrgId": null,
"sourceIp": "139.180.244.174",
"user": null,
"userAgent": "PostmanRuntime/7.20.1",
"userArn": null
},
"path": "/default/AWS_Lambda_REST_POC_INI2",
"protocol": "HTTP/1.1",
"requestId": "3e0cfe92-f221-44e1-becd-cc0d23bb77ce",
"requestTime": "03/Dec/2019:20:36:42 +0000",
"requestTimeEpoch": 1575405402973,
"resourceId": "md77fi",
"resourcePath": "/AWS_Lambda_REST_POC_INI2",
"stage": "default"
},
"resource": "/AWS_Lambda_REST_POC_INI2",
"stageVariables": null
}
Please help!
So are you trying to access "zipcode" from the JSON given above ? You said when you log $.event
you get the above one. To access zipCode from above event you'll need to do $.event.body[\"zipcode\"] or $.event.body.zipcode .
Hi Samip, I already tried that and it did not work.
In-affect, even in the above code, I am trying the same.
I am passing data into flow as 'CityCode_Input' and then trying to access 'zipcode' from that as $flow.CityCode_Input.zipcode
Can you do a small thing ? Can you output $flow.CityCode_Input.body
or just try accessing "body" part of the data. Not the 'ZipCode'. I suspect that the body should output "{\"zipcode\":\"07604\"}". If it does; that means it's a string and not an object. Hence you need to use "string" functions to get the code '07604'(like splitting and trimming). 'https://github.com/project-flogo/contrib/tree/master/function/string'
@akpuvvada , Samip is right the body is string not an object so to get the zipcode value you can use JSON path function.
Please try this json.path("$.zipcode", coerce.toObject($flow.CityCode_Input.body))
How do I map it in an activity input?
Add =
before json.path
Getting below error:
2019-12-04T20:42:51.942Z ERROR [flogo.activity.log] - Execution failed for Activity[log_2] in Flow[Lambda_GET_WeatherLimit_POC] - key error: zipcode not found in object
github.com/project-flogo/core/support/log.(*zapLoggerImpl).Errorf
@akpuvvada Can you share your app.json?
Hi Li, Sorry. My mappings were wrong. I updated it now and it is working. Thanks for the help. json.path and coerce helped.
What is your question? Trying to get data from AWS Lambda Trigger. What ever JSON I pass to API or SQS is coming as string as given below. I want to extract the data from that JSON - in this case zipcode value 07604.
"body": "{\"zipcode\":\"07604\"}",
I tried doing below. Pass input from trigger to flow as
CityCode_Input is defined as object.
Then I tried to get the data as
$flow.CityCode_Input.zipcode
. Re;avant code snippet below.Please tell us about your environment (Operating system, docker version, browser & web ui version, etc): AWS Lambda
Flogo version (CLI & contrib/lib. If unknown, leave empty or state unknown): 0.X.X Latest Version