Pulling out specific values from postman response and aggregating them - postman

I am getting below response in my Postman API request to pull a test execution report.
Notice that there are two set of values with "field_name": "Status". I want to aggregate these 2 values to get the following result:
Passed: 1
Unexecuted: 1
I read stuff on the internet, but could not find anything good. Appreciate the help!!
Response body JSON:
[
{
"parentId": 3171717,
"parentType": "test-cycle",
"automation": "No",
"links": [
{
"rel": "test-case",
"href": "xxxxxxx/api/v3/projects/20752/test-cases/27774385?versionId=37779716"
},
{
"rel": "test-cycle",
"href": "xxxxxxx/api/v3/projects/20752/test-cycles/3171717"
},
{
"rel": "self",
"href": "xxxxxxx/api/v3/projects/20752/test-runs/78572177"
}
],
"id": 78572177,
"name": "abcd test case",
"order": 2,
"pid": "TR-166875",
"created_date": "2018-12-05T06:05:32-05:00",
"last_modified_date": "2019-08-28T06:24:03-04:00",
"properties": [
{
"field_id": 2522370,
"field_name": "Run Order",
"field_value": ""
},
{
"field_id": 920264,
"field_name": "Execution Type",
"field_value": "501",
"field_value_name": "Functional"
},
{
"field_id": 920265,
"field_name": "Planned Start Date",
"field_value": "2016-12-23T05:00:00+00:00"
},
{
**"field_id": 920273,
"field_name": "Status",
"field_value": "605",
"field_value_name": "Unexecuted"**
},
{
"field_id": 920266,
"field_name": "Environment",
"field_value": ""
},
{
"field_id": 1055793,
"field_name": "Build Number",
"field_value": ""
},
{
"field_id": 920267,
"field_name": "Planned End Date",
"field_value": "2016-12-23T05:00:00+00:00"
},
{
"field_id": 1055794,
"field_name": "Build URL",
"field_value": ""
},
{
"field_id": 920269,
"field_name": "Target Release/Build",
"field_value": ""
},
{
"field_id": 1055795,
"field_name": "CI Tool",
"field_value": "",
"field_value_name": ""
},
{
"field_id": 920260,
"field_name": "Assigned To",
"field_value": "72843",
"field_value_name": "xxxxxxxx"
}
],
"test_case": {
"links": [],
"id": 27774385
},
"test_case_version_id": 37779716,
"test_case_version": "1.0",
"creator_id": 72843
},
{
"parentId": 3171717,
"parentType": "test-cycle",
"automation": "No",
"links": [
{
"rel": "test-case",
"href": "xxxxxxx/api/v3/projects/20752/test-cases/15957744?versionId=18722069"
},
{
"rel": "test-cycle",
"href": "xxxxxxx/api/v3/projects/20752/test-cycles/3171717"
},
{
"rel": "self",
"href": "xxxxxxx/api/v3/projects/20752/test-runs/26799694"
}
],
"id": 26799694,
"name": "xyzab",
"order": 1,
"pid": "TR-106714",
"created_date": "2017-11-26T23:48:28-05:00",
"last_modified_date": "2019-08-28T06:23:48-04:00",
"properties": [
{
"field_id": 2522370,
"field_name": "Run Order",
"field_value": ""
},
{
"field_id": 920264,
"field_name": "Execution Type",
"field_value": "501",
"field_value_name": "Functional"
},
{
"field_id": 920265,
"field_name": "Planned Start Date",
"field_value": "1989-12-31T05:00:00+00:00"
},
{
**"field_id": 920273,
"field_name": "Status",
"field_value": "601",
"field_value_name": "Passed"**
},
{
"field_id": 920266,
"field_name": "Environment",
"field_value": ""
},
{
"field_id": 1055793,
"field_name": "Build Number",
"field_value": ""
},
{
"field_id": 920267,
"field_name": "Planned End Date",
"field_value": "2016-12-23T05:00:00+00:00"
},
{
"field_id": 1055794,
"field_name": "Build URL",
"field_value": ""
},
{
"field_id": 920269,
"field_name": "Target Release/Build",
"field_value": ""
},
{
"field_id": 1055795,
"field_name": "CI Tool",
"field_value": "",
"field_value_name": ""
},
{
"field_id": 920260,
"field_name": "Assigned To",
"field_value": "22409",
"field_value_name": "xxxxxx"
}
],
"test_case": {
"links": [],
"id": 15957744
},
"test_case_version_id": 18722069,
"test_case_version": "1.0",
"creator_id": 31155
}
]

I was having a look at some local data and this might not work for you but you could give it a go:
let passed = 0
let unexecuted = 0
_.each(pm.response.json(), (data) => {
_.each(data.properties, (arrItem) => {
if(arrItem.field_name === "Status") {
if(arrItem.field_value_name === "Unexecuted") {
unexectued = unexectued + 1
}
else if (arrItem.field_value_name === "Passed"){
passed = passed + 1
}
}
})
})
console.log(`Passed: ${passed}`)
console.log(`Unexecuted: ${unexecuted}`)
I'm sure there are better ways to do this and I'm unsure about the performance of this code when using a larger data set but if you wanted something to work from and get a basic result in the console, this should work.

Related

highlighting bars in Deneb (Power BI) - fillOpacity

I have the chart on the left, code provided below, and would like to get the chart on the right. The chart on the right has the bars highlighted that correspond to a selected tier; the tier selected comes from a slicer. (The right chart shows Tier 1; however, the user may prefer a different tier.) I feel like this can be accomplished using fillOpacity. How do I get the highlighting?
{
"data": {
"values": [
{"name": "A", "group": "High", "tier": "Tier 3"},
{"name": "B", "group": "Med", "tier": "Tier 1"},
{"name": "C", "group": "High", "tier": "Tier 1"},
{"name": "D", "group": "High", "tier": "Tier 2"},
{"name": "E", "group": "Low", "tier": "Tier 3"},
{"name": "F", "group": "Low", "tier": "Tier 1"}
]
},
"transform": [
{
"aggregate": [
{
"field": "name",
"op": "count",
"as": "numProj"
}
],
"groupby": [
"name",
"group"
]
},
{
"stack": "numProj",
"groupby": ["group"],
"sort": [
{
"field": "name",
"order": "descending"
}
],
"as": "barTop"
}
],
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true
},
"encoding": {
"y": {
"field": "numProj",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": -10
},
"encoding": {
"y": {
"field": "barTop",
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}
Highlighting in Deneb is quite involved and can be read about here. Having said that, I have a working example.
Code
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 0.3
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 1
},
"encoding": {
"y": {
"field": "test__highlight",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": 70
},
"encoding": {
"y": {
"field": "test__highlight",
"stack": true,
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}
Things to keep in mind.
You need a measure (Deneb docs state highlighting doesn't work without a measure). The measure named test is simply test = COUNT('Table'[name])
You can't highlight from a slicer unless it is disconnected as slicers filter instead of highlight
You can't highlight stacks in position. The highlighted stacks naturally fall to the bottom as a result of how the data is being passed. There may be a way around this but it will involve further investigation which is probably not worth it.
Edit 1
Highlighting in place.
{
"data": {"name": "dataset"},
"layer": [
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true,
"opacity": 0.3
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "bar",
"stroke": "black",
"strokeWidth": 1,
"tooltip": true
},
"encoding": {
"y": {
"field": "test",
"type": "quantitative",
"axis": {
"title": "Number of Projects",
"tickMinStep": 1
}
},
"opacity": {
"condition": {
"test": "datum['test__highlight']!=null"
,
"value": 1
},
"value": 0
},
"fill": {
"field": "group",
"type": "nominal",
"scale": {
"domain": [
"Low",
"Med",
"High"
],
"range": [
"#e15759",
"#ffff00",
"#59a14f"
]
},
"legend": null
}
}
},
{
"mark": {
"type": "text",
"color": "black",
"dy": 70
},
"encoding": {
"y": {
"field": "test",
"stack": true,
"type": "quantitative"
},
"text": {
"field": "name"
}
}
}
],
"encoding": {
"x": {
"field": "group",
"type": "nominal",
"axis": {
"title": null,
"labelAngle": 0
}
}
}
}

How to configure dynamically a AWS Sage Maker task with AWS Step Function

I'm trying to build an ML pipeline using AWS Step Function.
I would like to configure the 'CreateHyperParameterTuningJob' dynamically depending on the input of the task.
Here is a screenshot of the State Machine that I'm trying to build:
ML State Machine
When I try to create this State Machine, I got the following error:
The value for the field 'MaxParallelTrainingJobs' must be an INTEGER
I'm struggling to figure out what is the issue here.
Do you have any suggestion to make the SM configuration dynamic with Step Function? Is it even possible?
Here is the input data passed to the 'Run training job' task:
{
"client_id": "test",
"training_job_definition": {
"AlgorithmSpecification": {
"TrainingImage": "433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
"TrainingInputMode": "File"
},
"ResourceConfig": {
"InstanceCount": 1,
"InstanceType": "ml.m5.large",
"VolumeSizeInGB": 5
},
"StaticHyperParameters": {
"num_round": 750
},
"StoppingCondition": {
"MaxRuntimeInSeconds": 900
},
"InputDataConfig": [
{
"ChannelName": "train",
"CompressionType": "None",
"ContentType": "csv",
"DataSource": {
"S3DataSource": {
"S3DataDistributionType": "FullyReplicated",
"S3DataType": "S3Prefix",
"S3Uri": "..."
}
}
},
{
"ChannelName": "validation",
"CompressionType": "None",
"ContentType": "csv",
"DataSource": {
"S3DataSource": {
"S3DataDistributionType": "FullyReplicated",
"S3DataType": "S3Prefix",
"S3Uri": "..."
}
}
}
],
"OutputDataConfig": {
"S3OutputPath": "..."
},
"RoleArn": "arn:aws:iam::679298748479:role/landingzone_sagemaker_role"
},
"hyper_parameter_tuning_job_config": {
"HyperParameterTuningJobObjective": {
"MetricName": "validation:rmse",
"Type": "Minimize"
},
"Strategy": "Bayesian",
"ResourceLimits": {
"MaxParallelTrainingJobs": 2,
"MaxNumberOfTrainingJobs": 10
},
"ParameterRanges": {
"ContinuousParameterRanges": [
{
"Name": "eta",
"MinValue": 0.01,
"MaxValue": 0.04
},
{
"Name": "gamma",
"MinValue": 0,
"MaxValue": 100
},
{
"Name": "subsample",
"MinValue": 0.6,
"MaxValue": 1
},
{
"Name": "lambda",
"MinValue": 0,
"MaxValue": 5
},
{
"Name": "alpha",
"MinValue": 0,
"MaxValue": 2
}
],
"IntegerParameterRanges": [
{
"Name": "max_depth",
"MinValue": 5,
"MaxValue": 10
}
]
}
}
}
Here is JSON file that describes the State Machine:
{
"StartAt": "Generate Training Dataset",
"States": {
"Generate Training Dataset": {
"Resource": "arn:aws:lambda:uswest-2:012345678912:function:StepFunctionsSample-SageMaLambdaForDataGeneration-1TF67BUE5A12U",
"Type": "Task",
"Next": "Run training job"
},
"Run training job": {
"Resource": "arn:aws:states:::sagemaker:createHyperParameterTuningJob.sync",
"Parameters": {
"HyperParameterTuningJobName.$": "$.execution_date",
"HyperParameterTuningJobConfig": {
"HyperParameterTuningJobObjective": {
"MetricName": "$.hyper_parameter_tuning_job_config.HyperParameterTuningJobObjective.MetricName",
"Type": "Minimize"
},
"Strategy": "$.hyper_parameter_tuning_job_config.Strategy",
"ResourceLimits": {
"MaxParallelTrainingJobs": "$.hyper_parameter_tuning_job_config.ResourceLimits.MaxParallelTrainingJobs",
"MaxNumberOfTrainingJobs": "$.hyper_parameter_tuning_job_config.ResourceLimits.MaxNumberOfTrainingJobs"
},
"ParameterRanges": "$.hyper_parameter_tuning_job_config.ParameterRanges"
},
"TrainingJobDefinition": {
"AlgorithmSpecification": "$.training_job_definition.AlgorithmSpecification",
"StoppingCondition": "$.training_job_definition.StoppingCondition",
"ResourceConfig": "$.training_job_definition.ResourceConfig",
"RoleArn": "$.training_job_definition.RoleArn",
"InputDataConfig": "$.training_job_definition.InputDataConfig",
"OutputDataConfig": "$.training_job_definition.OutputDataConfig",
"StaticHyperParameters": "$.training_job_definition.StaticHyperParameters"
},
"HyperParameterTuningJobConfig.ResourceLimits": ""
},
"Type": "Task",
"End": true
}
}
}

Is it possible to make a partial refund multiple times?

Is it possible to make partial refund using Authorize.Net? E.g. I have a transaction by 300$. First time I need to make a refund 100$ on this transaction. And second time to make a refund 50$.
What kind of transaction status will be after that?
first request:
...
"refId": "123456",
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": "100.00",}
"refTransId": "1234567890"
}
...
second request:
...
"refId": "123456",
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": "50.00",}
"refTransId": "1234567890"
}
...
Yes, you can make multiple refunds against one transaction as long as you do not go over the original transaction amount.
Below I made a $50 payment and then following up with a $20 and $10 refund. Both were successful.
Here is my original AUTH_CAPTURE request:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 38947161,
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": 100,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020",
"cardCode": "999"
}
},
"order": {
"invoiceNumber": "1324567890",
"description": "this is a test transaction"
},
"lineItems": {
"lineItem": [
{
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
},
{
"itemId": "2",
"name": "desk",
"description": "Big Desk",
"quantity": "10",
"unitPrice": "85.00"
}
]
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "18",
"email": "someone#blackhole.tv"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "allowPartialAuth",
"settingValue": "false"
},
{
"settingName": "duplicateWindow",
"settingValue": "0"
},
{
"settingName": "emailCustomer",
"settingValue": "false"
},
{
"settingName": "recurringBilling",
"settingValue": "false"
},
{
"settingName": "testRequest",
"settingValue": "false"
}
]
},
"userFields": {
"userField": {
"name": "favorite_color",
"value": "blue"
}
}
}
}
}
Here is my original AUTH_CAPTURE response:
{
"transactionResponse": {
"responseCode": "1",
"authCode": "TTJ26B",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "40032153203",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"userFields": [
{
"name": "favorite_color",
"value": "blue"
}
],
"transHashSha2": "0C9E5A47F93CD5B770A6B4AB24FE0F0D6F3B909066C72A10C4746F48C9886527A18B654736AE8D920D9048A14F2823A0DEC5B5F775A1C48DE9CBCF41C8D28CA3",
"SupplementalDataQualificationIndicator": 0
},
"refId": "38947161",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Here is my first REFUND request (successful):
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 30777668,
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": 20,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020"
}
},
"authCode": "40032153203"
}
}
}
Here is my first REFUND response (successful):
{
"transactionResponse": {
"responseCode": "1",
"authCode": "",
"avsResultCode": "P",
"cvvResultCode": "",
"cavvResultCode": "",
"transId": "40032153314",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "4CE2D83B56C09494AD5609440E3337A6DEE0F4C74FBC99B218D65F6A121EFFC269F8954AC47C17B3B739E61A860C7B0818A8497D85D314D6E0CD89C9FE71A071",
"SupplementalDataQualificationIndicator": 0
},
"refId": "30777668",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Here is my second REFUND request (successful):
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "",
"transactionKey": ""
},
"refId": 40597686,
"transactionRequest": {
"transactionType": "refundTransaction",
"amount": 10,
"payment": {
"creditCard": {
"cardNumber": "4111111111111111",
"expirationDate": "122020"
}
},
"authCode": "40032153203"
}
}
}
Here is my second REFUND response (successful):
{
"transactionResponse": {
"responseCode": "1",
"authCode": "",
"avsResultCode": "P",
"cvvResultCode": "",
"cavvResultCode": "",
"transId": "40032153319",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX1111",
"accountType": "Visa",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "FD146FC0F8F3F31068905EC6C8D252662AA735ACDFAC53B4A8D808060C244C06288700AA8872466C3E240B62130D010CFBDE0473D09B631514A6E2E2CB77804F",
"SupplementalDataQualificationIndicator": 0
},
"refId": "40597686",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}

How to create payment profile with the create transaction request on Authorize.net

I would like to create the payment profile with the createTransactionRequest.
Here are the request parameters that i am passing.
{
"createTransactionRequest":{
"merchantAuthentication":{
"name":"***",
"transactionKey":"***"
},
"transactionRequest":{
"transactionType":"authCaptureTransaction",
"amount":"4.95",
"payment":{
"creditCard":{
"cardNumber":"5424000000000015",
"expirationDate":"1217",
"cardCode":123
}
},
"billTo":{
"firstName":"first name",
"lastName":"last name",
"address":"test address",
"city":"test city",
"state":"TX",
"zip":"12345",
"country":"USA"
},
"profile":{
"createProfile":true
}
}
}
}
and here is the response error.
{
"messages":{
"resultCode":"Error",
"message":[
{
"code":"E00003",
"text":"The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'profile' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'shipTo, customerIP, cardholderAuthentication, retail, employeeId, transactionSettings, userFields, surcharge, merchantDescriptor, subMerchant, tip' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'."
}
]
}
}
The order of the fields in your request matter. They must match what is in the documentation. That means that field needs to come before the billTo field in your JSON:
{
"createTransactionRequest":{
"merchantAuthentication":{
"name":"***",
"transactionKey":"***"
},
"transactionRequest":{
"transactionType":"authCaptureTransaction",
"amount":"4.95",
"payment":{
"creditCard":{
"cardNumber":"5424000000000015",
"expirationDate":"1217",
"cardCode":123
}
},
"profile":{
"createProfile":true
},
"billTo":{
"firstName":"first name",
"lastName":"last name",
"address":"test address",
"city":"test city",
"state":"TX",
"zip":"12345",
"country":"USA"
},
}
}
}
This request yields me this response:
{
"transactionResponse": {
"responseCode": "1",
"authCode": "Y77MQH",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "40007520179",
"refTransID": "",
"transHash": "94D188D090B695D7C6D47D9293840BE3",
"testRequest": "0",
"accountNumber": "XXXX0015",
"accountType": "MasterCard",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "9768048279544EDB22BAAAC194CA3EDBA705FBC569AC9555F3A2A86E545938849CEB2D9519885A4CC69328BBB7DDC36E0852998CAD5FAC1F6CA6427599E3493B"
},
"profileResponse": {
"messages": {
"resultCode": "Error",
"message": [
{
"code": "E00102",
"text": "Customer Info is missing."
}
]
}
},
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Looks like you need to add the id field in the customer section:
{
"createTransactionRequest":{
"merchantAuthentication":{
"name":"***",
"transactionKey":"***"
},
"transactionRequest":{
"transactionType":"authCaptureTransaction",
"amount":"4.95",
"payment":{
"creditCard":{
"cardNumber":"5424000000000015",
"expirationDate":"1217",
"cardCode":123
}
},
"profile":{
"createProfile":true
},
"customer":{
"id":<yourIdForThisUser>
},
"billTo":{
"firstName":"first name",
"lastName":"last name",
"address":"test address",
"city":"test city",
"state":"TX",
"zip":"12345",
"country":"USA"
},
}
}
}
That yields:
{
"transactionResponse": {
"responseCode": "1",
"authCode": "SCSVNX",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "40007520393",
"refTransID": "",
"transHash": "DFB7FE5B8D3FAFE0A18A6B5C125838A3",
"testRequest": "0",
"accountNumber": "XXXX0015",
"accountType": "MasterCard",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"transHashSha2": "57C6A161A948E5A7F5303FCD2FE8CDF3E1D3C38B989161675D47FD61526F3DA9EDBD497169F978860B78A2C5FEC1B6E54807086DF4B0CE346538DDDD9E25C4A8"
},
"profileResponse": {
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
},
"customerProfileId": "1502546960",
"customerPaymentProfileIdList": [
"1502081232"
],
"customerShippingAddressIdList": []
},
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}

Hypen in response data is throwing error when setting as global variable for nested response

I have a post man request. Which returns a response data as:
[
{
"id": "7ca27c09-2b67-417e-b367-f97d49824a2f",
"tags": [],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "Male",
"surgeryDate": {
"value": "2017-06-06"
},
"surgeryType": {
"value": "gastricBand"
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "",
"firstName": "name1",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 35,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner",
"createdDateTime": "2017-06-08T16:08:32.497Z",
"lastModifiedDateTime": "2017-06-09T13:23:03.503Z"
},
{
"id": "091b5ebd-b096-436e-a703-f97f0ae77baf",
"tags": [
"Application-Profile"
],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "",
"surgeryDate": {
"value": "2017-06-01"
},
"surgeryType": {
"value": ""
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "Dev",
"firstName": "Kat",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 41,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner Weightloss",
"createdDateTime": "2017-06-03T16:19:57.811Z",
"lastModifiedDateTime": "2017-06-08T16:07:49.555Z"
}
]
I need to extract the value of the emailid and set as global variable.
here is my code:
var jsonData1 = JSON.parse(responseBody);
postman.setGlobalVariable("jsonData1",jsonData1.profile.User-Profile.PII.mail);
But I am getting error. "User is undefined".
The problem here is that the hyphen / minus sign is interpreted as the subtraction operator.
Consider changing your API and using "userProfile" instead of "User-Profile".