suiteql inventory balance missing item when request committedQtyPerLocation - netsuite

I am using suiteql to find some inventory. With these 2 requests, I find 3 results, as expected:
{
"q": "select nvl( BUILTIN.DF(item), 'missing part' ) as Part, nvl( BUILTIN.DF(location), 'missing location' ) as LocationName, quantityAvailable from inventoryBalance where BUILTIN.DF(item) like 'TS2%'"
}
{
"q": "select item, quantityAvailable from inventoryBalance where item = 8457"
}
But with these 2 requests, I found no results:
{
"q": "select nvl( BUILTIN.DF(item), 'missing part' ) as Part, nvl( BUILTIN.DF(location), 'missing location' ) as LocationName, quantityAvailable, committedQtyPerLocation from inventoryBalance where BUILTIN.DF(item) like 'TS2%'"
}
{
"q": "select item, quantityAvailable, committedQtyPerLocation from inventoryBalance where item = 8457"
}
Why does adding the column "committedQtyPerLocation" cause my request to return nothing, with no errors?
Note that I get back results for other items if I remove the where clause, as per the below:
{
"q": "select nvl( BUILTIN.DF(item), 'missing part' ) as Part, nvl( BUILTIN.DF(location), 'missing location' ) as LocationName, quantityAvailable, committedQtyPerLocation from inventoryBalance"
}
Just not my TS2 part. In case you are wondering, below is the results based on the above lookup. Note that I shows committerqtyperlocation for some of the items:
{
"links": [
{
"rel": "self",
"href": "https://<account>.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql"
}
],
"count": 832,
"hasMore": false,
"items": [
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT Main",
"part": "Test Inventory Item",
"quantityavailable": "10"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Damages",
"part": "Test Inventory Item",
"quantityavailable": "-1"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Receiving",
"part": "Test Lot Inv",
"quantityavailable": "5"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Receiving",
"part": "Test Lot Inv",
"quantityavailable": "1"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "Sculley Warehouse",
"part": "DELETE-229205B",
"quantityavailable": "10"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Receiving",
"part": "DELETE-229205B",
"quantityavailable": "4"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Kitting",
"part": "DELETE-229205B",
"quantityavailable": "10"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Kitting",
"part": "355271",
"quantityavailable": "1"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Receiving",
"part": "201505",
"quantityavailable": "10"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Receiving",
"part": "2230-00",
"quantityavailable": "3"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "Sculley Warehouse",
"part": "2230-00",
"quantityavailable": "5"
},
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "CELLTREAT - Damages",
"part": "2230-00",
"quantityavailable": "1"
},
{
"links": [],
"committedqtyperlocation": "22",
"locationname": "CELLTREAT - Shipping",
"part": "2230-00",
"quantityavailable": "922"
},
...
{
"links": [],
"committedqtyperlocation": "0",
"locationname": "VistaLab - MAIN",
"part": "4060-3332",
"quantityavailable": "150"
}
],
"offset": 0,
"totalResults": 882
}
If I remove the committedQtyPerLocation from the request, as below, my TS2 item shows up:
{
"q": "select nvl( BUILTIN.DF(item), 'missing part' ) as Part, nvl( BUILTIN.DF(location), 'missing location' ) as LocationName, quantityAvailable from inventoryBalance"
}
The total "count" for this one is 882, so this proves that we are missing 50 inventoryBalance records when I add "committedQtyPerLocation.

Related

Loadrunner json parser

Requirement- from below code snippet, i need to pull data related to market segment= unicare.
in the subsequent request need to pass both state and market segment unicare..
first i need to find do i see unicare market segement.. if Yes what is the first occurance and its associated state. to be captured and placed in the consequent request.
tried lr_json_get_values. can you please help on this.
{
"taxID": "23424",
"firstName": "afsafa",
"lastName": "asdfsfa",
"middleName": "adfasad",
"npn": "324322424",
"stateResident": "WI",
"dateBirth": "234324224",
"licenseDetails": [
{
"state": "CO",
"license": [
{
"licenseNum": "3234224",
"dateUpdated": "12/08/2020",
"dateIssueLicenseOrg": "324242",
"dateExpireLicense": "243242",
"licenseClass": "avadfa Producer",
"licenseClassCode": "2",
"residencyStatus": "444",
"active": "Yes",
"details": [
{
"loa": "aafafafa",
"loaCode": "44444",
"authorityIssueDate": "44345353",
"status": "Active",
"statusReasonDate": "444444",
"ceCompliance": "N/S",
"ceCreditsNeeded": "0"
}
]
}
],
"address": [
{
"dateUpdated": "423333",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "asssss",
"nameCity": "aaaa",
"nameState": "WI",
"zip": "4444444",
"country": "U.S.A."
},
{
"dateUpdated": "10/22/2020",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "Fhk sfsfsafs",
"addrLine2": "6sdfsfsfa Ave",
"nameCity": "dfsafa",
"nameState": "WI",
"zip": "sdfsaff",
"country": "U.S.A."
},
{
"dateUpdated": "45353",
"addressTypeCode": "1",
"addrType": "45adfa",
"addrLine1": "1sfsafaf",
"nameCity": "adfafafa",
"nameState": "WI",
"zip": "34444-434",
"country": "U.S.A."
}
],
"brands": [
"ALWAYS"
],
"marketSegment": [
{
"brandName": "ALWAYS",
"lobTypes": [
"Individual",
"Senior"
]
},
{
"brandName": "Unicare",
"lobTypes": [
"Individual",
"Senior",
"Small Group",
"Large Group"
]
}
],
"isLifeExists": false
},
{
"state": "FL",
"license": [
{
"licenseNum": "3234224",
"dateUpdated": "12/08/2020",
"dateIssueLicenseOrg": "324242",
"dateExpireLicense": "243242",
"licenseClass": "avadfa Producer",
"licenseClassCode": "2",
"residencyStatus": "444",
"active": "Yes",
"details": [
{
"loa": "aafafafa",
"loaCode": "44444",
"authorityIssueDate": "44345353",
"status": "Active",
"statusReasonDate": "444444",
"ceCompliance": "N/S",
"ceCreditsNeeded": "0"
}
]
}
],
"address": [
{
"dateUpdated": "423333",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "asssss",
"nameCity": "aaaa",
"nameState": "WI",
"zip": "4444444",
"country": "U.S.A."
},
{
"dateUpdated": "10/22/2020",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "Fhk sfsfsafs",
"addrLine2": "6sdfsfsfa Ave",
"nameCity": "dfsafa",
"nameState": "WI",
"zip": "sdfsaff",
"country": "U.S.A."
},
{
"dateUpdated": "45353",
"addressTypeCode": "1",
"addrType": "45adfa",
"addrLine1": "1sfsafaf",
"nameCity": "adfafafa",
"nameState": "WI",
"zip": "34444-434",
"country": "U.S.A."
}
],
"brands": [],
"marketSegment": [
{
"brandName": "Unicare",
"lobTypes": [
"Individual",
"Senior",
"Small Group",
"Large Group"
]
}
],
"isLifeExists": false
},
{
"state": "WI",
"license": [
{
"licenseNum": "3234224",
"dateUpdated": "12/08/2020",
"dateIssueLicenseOrg": "324242",
"dateExpireLicense": "243242",
"licenseClass": "avadfa Producer",
"licenseClassCode": "2",
"residencyStatus": "444",
"active": "Yes",
"details": [
{
"loa": "aafafafa",
"loaCode": "44444",
"authorityIssueDate": "44345353",
"status": "Active",
"statusReasonDate": "444444",
"ceCompliance": "N/S",
"ceCreditsNeeded": "0"
}
]
}
],
"address": [
{
"dateUpdated": "423333",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "asssss",
"nameCity": "aaaa",
"nameState": "WI",
"zip": "4444444",
"country": "U.S.A."
},
{
"dateUpdated": "10/22/2020",
"addressTypeCode": "2",
"addrType": "adfafa",
"addrLine1": "Fhk sfsfsafs",
"addrLine2": "6sdfsfsfa Ave",
"nameCity": "dfsafa",
"nameState": "WI",
"zip": "sdfsaff",
"country": "U.S.A."
},
{
"dateUpdated": "45353",
"addressTypeCode": "1",
"addrType": "45adfa",
"addrLine1": "1sfsafaf",
"nameCity": "adfafafa",
"nameState": "WI",
"zip": "34444-434",
"country": "U.S.A."
}
],
"brands": [
"ALWAYS",
"WCICWCICsd(sdfsafasdfsa COLLABORATIVE sdfsfsdf COMP)"
],
"marketSegment": [
{
"brandName": "ALWAYS",
"lobTypes": [
"Individual",
"Senior",
"Small Group",
"Large Group"
]
},
{
"brandName": "WCICsd(sdfsafasdfsa COLLABORATIVE sdfsfsdf COMP)",
"lobTypes": [
"Individual",
"Small Group",
"Large Group"
]
},
{
"brandName": "Unicare",
"lobTypes": [
"Individual",
"Senior",
"Small Group",
"Large Group"
]
}
],
"isLifeExists": true
}
]
}

How to update a subscription (adding a pricing plan) by Stripe in Node.js?

I'm building a web app which sells several products, each product corresponds to a pricing plan. All the payment system is managed by Stripe.
It happens very often that a user has a subscription that contains Product A (i.e., one pricing plan), and then he wants to add Product B (i.e., another pricing plan) to the same subscription. I want to know how to achieve this by APIs of Stripe.
There is a webpage of Stripe to update a subscription (e.g., https://dashboard.stripe.com/test/subscriptions/sub_H4pQGW8nnc80vF/edit where sub_H4pQGW8nnc80vF is the subscription ID). Let's assume this customer already has 1 Verificator in the subscription, and then he wants to add 1 Pretty Formula to the same subscription. I do this update via the website. Here is the log:
Here is the full Request POST body:
{
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
"off_session": "true",
"prorate": "true",
"cancel_at": "",
"days_until_due": "30",
"default_tax_rates": "",
"collection_method": "send_invoice",
"billing_thresholds": "",
"enable_incomplete_payments": "false",
"invoice_settings": {
"description": "",
"send_hosted_payment_email": "true",
"supported_payment_methods": {
"ach_credit_transfer": "false",
"au_becs_debit": "false",
"bancontact": "false",
"card": "true",
"fpx": "false",
"giropay": "false",
"ideal": "false",
"jp_credit_transfer": "false",
"paper_check": "false",
"sepa_credit_transfer": "false",
"sofort": "false"
},
"custom_fields": "",
"footer": ""
},
"default_payment_method": "",
"default_source": ""
}
Here is the full Response body:
{
"id": "sub_H4pQGW8nnc80vF",
"object": "subscription",
"application_fee_percent": null,
"billing_cycle_anchor": 1586597833,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"collection_method": "send_invoice",
"created": 1586597833,
"current_period_end": 1589189833,
"current_period_start": 1586597833,
"customer": "5e575130651c5721d808d25b",
"customer_email": "sdtikply#gmail.com",
"customer_name": "Thomas Joseph",
"days_until_due": 30,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [
],
"discount": null,
"ended_at": null,
"invoice_settings": {
"send_hosted_payment_email": true,
"supported_payment_methods": {
"ach_credit_transfer": false,
"au_becs_debit": false,
"bancontact": false,
"card": true,
"fpx": false,
"giropay": false,
"ideal": false,
"jp_credit_transfer": false,
"paper_check": false,
"sepa_credit_transfer": false,
"sofort": false
}
},
"items": {
"object": "list",
"data": [
{
"id": "si_H4pQal4ZxGzLbW",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1586597833,
"metadata": {
},
"plan": {
"id": "plan_Ga6n9yMYCDnHCu",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1579512574,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Verificator",
"nickname": "Verificator",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_Ga6mVdA8KXyZ8I",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
},
{
"id": "si_H82ES9BdIKZCNG",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1587337381,
"metadata": {
},
"plan": {
"id": "plan_Gz6i9yPVIjrDPX",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1585278262,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Pretty Formula",
"nickname": "Pretty Formula",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_GxqkRFdI08DvyR",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/subscription_items?subscription=sub_H4pQGW8nnc80vF"
},
"latest_invoice": "in_1GWfm1EV4K2GahYLlmtUEISo",
"livemode": false,
"metadata": {
},
"next_pending_invoice_item_invoice": null,
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"pause_collection": null,
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"plan": null,
"quantity": null,
"schedule": null,
"start_date": 1586597833,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
So my question is, how can I code in my backend (Node.js) to achieve exactly the same thing?
You just need to use the Update Subscription API and provide the items portion just as you're seeing above:
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
The first item is the existing Subscription Item (si_), and the second one is the new one you want to add.

Passing all files in a folder via Terraform

I'm building a monitoring stack for our internal projects. I would like for them to be able to design their own monitoring dashboards to be used inside Grafana so I cannot predict what those will be called.
I created a folder called grafana_dashboard, where I will be instructing them to store their dashboard as JSON files and I want to pass all the contents of that folder to the Grafana instance.
I have tried a number of variations of this :
resource "grafana_dashboard" "dashboards" {
for_each = fileset(path.module, "grafana_dashboard/*.json")
config_json = "${each.key}"
depends_on = [aiven_service.grafana]
}
But keep getting this error:
Error: invalid character 'g' looking for beginning of value
on ../modules/monitoring/grafana.tf line 139, in resource "grafana_dashboard" "dashboards":
139: resource "grafana_dashboard" "dashboards" {
Can any of you see what I'm doing wrong?
Here's an example of one of the .json files i'm trying to pass:
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
},
{
"datasource": "Prometheus",
"enable": true,
"expr": "sum(changes(nginx_ingress_controller_config_last_reload_successful_timestamp_seconds{instance!=\"unknown\",controller_class=~\"$controller_class\",namespace=~\"$namespace\"}[30s])) by (controller_class)",
"hide": false,
"iconColor": "rgba(255, 96, 96, 1)",
"limit": 100,
"name": "Config Reloads",
"showIn": 0,
"step": "30s",
"tagKeys": "controller_class",
"tags": [],
"titleFormat": "Config Reloaded",
"type": "tags"
}
]
},
"description": "Ingress-nginx supports a rich collection of prometheus metrics. If you have prometheus and grafana installed on your cluster then prometheus will already be scraping this data due to the scrape annotation on the deployment.",
"editable": false,
"gnetId": 9614,
"graphTooltip": 0,
"id": 18,
"iteration": 1574177838584,
"links": [],
"panels": [
{
"columns": [
{
"text": "Current",
"value": "current"
}
],
"datasource": "Prometheus",
"fontSize": "100%",
"gridPos": {
"h": 15,
"w": 24,
"x": 0,
"y": 0
},
"height": "1024",
"id": 85,
"links": [],
"options": {},
"pageSize": 15,
"scroll": true,
"showHeader": true,
"sort": {
"col": 1,
"desc": false
},
"styles": [
{
"alias": "Time",
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"pattern": "Time",
"type": "date"
},
{
"alias": "TTL",
"colorMode": "cell",
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Current",
"thresholds": [
"0",
"691200"
],
"type": "number",
"unit": "s"
},
{
"alias": "",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"decimals": 2,
"pattern": "/.*/",
"thresholds": [],
"type": "number",
"unit": "short"
}
],
"targets": [
{
"expr": "avg(nginx_ingress_controller_ssl_expire_time_seconds{kubernetes_pod_name=~\"$controller\",namespace=~\"$namespace\",ingress=~\"$ingress\"}) by (host) - time()",
"format": "time_series",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ host }}",
"metric": "gke_letsencrypt_cert_expiration",
"refId": "A",
"step": 1
}
],
"title": "Ingress Certificate Expiry",
"transform": "timeseries_aggregations",
"type": "table"
}
],
"refresh": "5s",
"schemaVersion": 19,
"style": "dark",
"tags": [
"nginx"
],
"templating": {
"list": [
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Namespace",
"multi": false,
"name": "namespace",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash, controller_namespace)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Controller Class",
"multi": false,
"name": "controller_class",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash{namespace=~\"$namespace\"}, controller_class) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Controller",
"multi": false,
"name": "controller",
"options": [],
"query": "label_values(nginx_ingress_controller_config_hash{namespace=~\"$namespace\",controller_class=~\"$controller_class\"}, controller_pod) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {
"text": "All",
"value": "$__all"
},
"datasource": "Prometheus",
"definition": "",
"hide": 0,
"includeAll": true,
"label": "Ingress",
"multi": false,
"name": "ingress",
"options": [],
"query": "label_values(nginx_ingress_controller_requests{namespace=~\"$namespace\",controller_class=~\"$controller_class\",controller=~\"$controller\"}, ingress) ",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 2,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"2m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "browser",
"title": "Cert-manager",
"uid": "nginx",
"version": 12
}
This works, so I know that I can do it, but doesn't suit my needs as I'd need to hardcode the name of each file:
resource "grafana_dashboard" "nginx_ingress_controller" {
config_json = templatefile("${path.module}/grafana_dashboard/nginx-ingress-controller.json", { DS_PROMETHEUS = local.prometheus_datasource_name })
depends_on = [aiven_service.grafana]
}
You need to actually use the file contents in your config_json parameter to the grafana_dashboard.
Switching your resource definition to the following should be enough:
resource "grafana_dashboard" "dashboards" {
for_each = fileset(path.module, "grafana_dashboard/*.json")
config_json = file("${path.module}/${each.key}")
depends_on = [aiven_service.grafana]
}

create contact from node.js to mautic uisng Mautic rest api

I am using mautic-node npm module for contacting mautic REST API from node.js.My aim is to create a contact from my app in mautic dashboard using mautic REST API,but i am facing issue in creating contact from node.js.Please help me to figure out this.
var mautic = require('mautic-api-node');
var request = require('request');
var config = require('../config/config.js');
var request = require('request');
exports.saveContact = (req, res) => {
queryParameters = JSON.stringify(req.body);
var username = "mauticUsername";
var password = "mauticPassword";
var auth = "Basic " + new Buffer.from(username + ":" +
password).toString("base64");
var options = {
url: 'https://mautic-url/api/contacts/new',
method: "POST",
form: queryParameters,
headers: {
"Authorization": auth
}
};
request(options, (error, response, body) => {
if (error) console.log(error);
console.log("Body", body);
})
}
I am passing this request body to backend:-
{
"firstname":"firstname",
"ipAddress":"Ipaddress",
"lastname":"lastname",
"email":"email"
}
when i run this code i am getting this response
Body {
"contact": {
"isPublished": true,
"dateAdded": "2019-06-08T10:06:25+00:00",
"dateModified": null,
"createdBy": 1,
"createdByUser": "username",
"modifiedBy": null,
"modifiedByUser": null,
"id": 1277,
"points": 0,
"color": null,
"fields": {
"core": {
"title": {
"id": 1,
"group": "core",
"label": "Title",
"alias": "title",
"type": "lookup",
"value": null
},
"firstname": {
"id": 2,
"group": "core",
"label": "First Name",
"alias": "firstname",
"type": "text",
"value": null
},
"lastname": {
"id": 3,
"group": "core",
"label": "Last Name",
"alias": "lastname",
"type": "text",
"value": null
},
"company": {
"id": 4,
"group": "core",
"label": "Primary company",
"alias": "company",
"type": "text",
"value": null
},
"position": {
"id": 5,
"group": "core",
"label": "Position",
"alias": "position",
"type": "text",
"value": null
},
"email": {
"id": 6,
"group": "core",
"label": "Email",
"alias": "email",
"type": "email",
"value": null
},
"mobile": {
"id": 7,
"group": "core",
"label": "Mobile",
"alias": "mobile",
"type": "tel",
"value": null
},
"phone": {
"id": 8,
"group": "core",
"label": "Phone",
"alias": "phone",
"type": "tel",
"value": null
},
"points": {
"id": 9,
"group": "core",
"label": "Points",
"alias": "points",
"type": "number",
"value": null
},
"fax": {
"id": 10,
"group": "core",
"label": "Fax",
"alias": "fax",
"type": "tel",
"value": null
},
"address1": {
"id": 11,
"group": "core",
"label": "Address Line 1",
"alias": "address1",
"type": "text",
"value": null
},
"address2": {
"id": 12,
"group": "core",
"label": "Address Line 2",
"alias": "address2",
"type": "text",
"value": null
},
"city": {
"id": 13,
"group": "core",
"label": "City",
"alias": "city",
"type": "text",
"value": null
},
"state": {
"id": 14,
"group": "core",
"label": "State",
"alias": "state",
"type": "region",
"value": null
},
"zipcode": {
"id": 15,
"group": "core",
"label": "Zip Code",
"alias": "zipcode",
"type": "text",
"value": null
},
"country": {
"id": 16,
"group": "core",
"label": "Country",
"alias": "country",
"type": "country",
"value": null
},
"preferred_locale": {
"id": 17,
"group": "core",
"label": "Preferred Locale",
"alias": "preferred_locale",
"type": "locale",
"value": null
},
"timezone": {
"id": 18,
"group": "core",
"label": "mautic.lead.field.timezone",
"alias": "timezone",
"type": "timezone",
"value": null
},
"last_active": {
"id": 19,
"group": "core",
"label": "Date Last Active",
"alias": "last_active",
"type": "datetime",
"value": null
},
"attribution_date": {
"id": 20,
"group": "core",
"label": "Attribution Date",
"alias": "attribution_date",
"type": "datetime",
"value": null
},
"attribution": {
"id": 21,
"group": "core",
"label": "Attribution",
"alias": "attribution",
"type": "number",
"value": null
},
"website": {
"id": 22,
"group": "core",
"label": "Website",
"alias": "website",
"type": "url",
"value": null
}
},
"social": {
"facebook": {
"id": 23,
"group": "social",
"label": "Facebook",
"alias": "facebook",
"type": "text",
"value": null
},
"foursquare": {
"id": 24,
"group": "social",
"label": "Foursquare",
"alias": "foursquare",
"type": "text",
"value": null
},
"googleplus": {
"id": 25,
"group": "social",
"label": "Google+",
"alias": "googleplus",
"type": "text",
"value": null
},
"instagram": {
"id": 26,
"group": "social",
"label": "Instagram",
"alias": "instagram",
"type": "text",
"value": null
},
"linkedin": {
"id": 27,
"group": "social",
"label": "LinkedIn",
"alias": "linkedin",
"type": "text",
"value": null
},
"skype": {
"id": 28,
"group": "social",
"label": "Skype",
"alias": "skype",
"type": "text",
"value": null
},
"twitter": {
"id": 29,
"group": "social",
"label": "Twitter",
"alias": "twitter",
"type": "text",
"value": null
}
},
"personal": [],
"professional": [],
"all": {
"id": 1277,
"title": null,
"firstname": null,
"lastname": null,
"company": null,
"position": null,
"email": null,
"mobile": null,
"phone": null,
"points": null,
"fax": null,
"address1": null,
"address2": null,
"city": null,
"state": null,
"zipcode": null,
"country": null,
"preferred_locale": null,
"timezone": null,
"last_active": null,
"attribution_date": null,
"attribution": null,
"website": null,
"facebook": null,
"foursquare": null,
"googleplus": null,
"instagram": null,
"linkedin": null,
"skype": null,
"twitter": null
}
},
"lastActive": null,
"owner": null,
"ipAddresses": [],
"tags": [],
"utmtags": null,
"stage": null,
"dateIdentified": null,
"preferredProfileImage": null,
"doNotContact": [],
"frequencyRules": []
}
}
This is the response of GET contacts API i guess so i am confused why i am getting GET API response while doing POST request to contact API please help me to figure out this issue.
As you can see in the picture, when you create a new contact along with response status code it returns the properties as well which are similar to "Get Contact" request(as you will get when you get contact by id). So I think as long as your new contact is being created in mautic you shouldn't be worried.

search json file with python script

I have following tfstate file (it has JSON structure)
{
"version": 3,
"terraform_version": "0.11.1",
"serial": 1,
"lineage": "4d050905-8f3d-46df-8bbb-8859c708abe7",
"modules": [
{
"path": [
"root"
],
"outputs": {
"id": {
"sensitive": false,
"type": "list",
"value": [
"34.244.138.72",
"34.249.95.222"
]
}
},
"resources": {
"aws_instance.win-example.0": {
"type": "aws_instance",
"depends_on": [
"aws_security_group.DJukes"
],
"primary": {
"id": "i-0f8c0fcb36f58947d",
"attributes": {
"ami": "ami-cc821eb5",
"associate_public_ip_address": "true",
"availability_zone": "eu-west-1a",
"disable_api_termination": "false",
"ebs_block_device.#": "0",
"ebs_optimized": "false",
"ephemeral_block_device.#": "0",
"iam_instance_profile": "",
"id": "i-0f8c0fcb36f58947d",
"instance_state": "running",
"instance_type": "t2.medium",
"ipv6_addresses.#": "0",
"key_name": "",
"monitoring": "false",
"network_interface.#": "0",
"network_interface_id": "eni-8dbf17be",
"placement_group": "",
"primary_network_interface_id": "eni-8dbf17be",
"private_dns": "ip-172-31-30-138.eu-west-1.compute.internal",
"private_ip": "172.31.30.138",
"public_dns": "ec2-34-244-138-72.eu-west-1.compute.amazonaws.com",
"public_ip": "34.244.138.72",
"root_block_device.#": "1",
"root_block_device.0.delete_on_termination": "true",
"root_block_device.0.iops": "100",
"root_block_device.0.volume_id": "vol-0dcfa45e001323eac",
"root_block_device.0.volume_size": "30",
"root_block_device.0.volume_type": "gp2",
"security_groups.#": "1",
"security_groups.4272775738": "DJukes",
"source_dest_check": "true",
"subnet_id": "subnet-5b50a512",
"tags.%": "1",
"tags.Name": "DJukes-1",
"tenancy": "default",
"user_data": "fad67bb12b32d15c3f5156bf7bdd830d4e084c6f",
"volume_tags.%": "0",
"vpc_security_group_ids.#": "1",
"vpc_security_group_ids.2187737336": "sg-fd5adf87"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 600000000000,
"delete": 600000000000,
"update": 600000000000
},
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
},
"aws_instance.win-example.1": {
"type": "aws_instance",
"depends_on": [
"aws_security_group.DJukes"
],
"primary": {
"id": "i-0bb714a7ddd376599",
"attributes": {
"ami": "ami-cc821eb5",
"associate_public_ip_address": "true",
"availability_zone": "eu-west-1a",
"disable_api_termination": "false",
"ebs_block_device.#": "0",
"ebs_optimized": "false",
"ephemeral_block_device.#": "0",
"iam_instance_profile": "",
"id": "i-0bb714a7ddd376599",
"instance_state": "running",
"instance_type": "t2.medium",
"ipv6_addresses.#": "0",
"key_name": "",
"monitoring": "false",
"network_interface.#": "0",
"network_interface_id": "eni-dab018e9",
"placement_group": "",
"primary_network_interface_id": "eni-dab018e9",
"private_dns": "ip-172-31-24-177.eu-west-1.compute.internal",
"private_ip": "172.31.24.177",
"public_dns": "ec2-34-249-95-222.eu-west-1.compute.amazonaws.com",
"public_ip": "34.249.95.222",
"root_block_device.#": "1",
"root_block_device.0.delete_on_termination": "true",
"root_block_device.0.iops": "100",
"root_block_device.0.volume_id": "vol-079b3491295b06249",
"root_block_device.0.volume_size": "30",
"root_block_device.0.volume_type": "gp2",
"security_groups.#": "1",
"security_groups.4272775738": "DJukes",
"source_dest_check": "true",
"subnet_id": "subnet-5b50a512",
"tags.%": "1",
"tags.Name": "DJukes-2",
"tenancy": "default",
"user_data": "fad67bb12b32d15c3f5156bf7bdd830d4e084c6f",
"volume_tags.%": "0",
"vpc_security_group_ids.#": "1",
"vpc_security_group_ids.2187737336": "sg-fd5adf87"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 600000000000,
"delete": 600000000000,
"update": 600000000000
},
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
},
"aws_security_group.DJukes": {
"type": "aws_security_group",
"depends_on": [],
"primary": {
"id": "sg-fd5adf87",
"attributes": {
"description": "Managed by Terraform",
"egress.#": "1",
"egress.482069346.cidr_blocks.#": "1",
"egress.482069346.cidr_blocks.0": "0.0.0.0/0",
"egress.482069346.description": "",
"egress.482069346.from_port": "0",
"egress.482069346.ipv6_cidr_blocks.#": "0",
"egress.482069346.prefix_list_ids.#": "0",
"egress.482069346.protocol": "-1",
"egress.482069346.security_groups.#": "0",
"egress.482069346.self": "false",
"egress.482069346.to_port": "0",
"id": "sg-fd5adf87",
"ingress.#": "1",
"ingress.2601213444.cidr_blocks.#": "1",
"ingress.2601213444.cidr_blocks.0": "0.0.0.0/0",
"ingress.2601213444.description": "",
"ingress.2601213444.from_port": "0",
"ingress.2601213444.ipv6_cidr_blocks.#": "0",
"ingress.2601213444.protocol": "tcp",
"ingress.2601213444.security_groups.#": "0",
"ingress.2601213444.self": "false",
"ingress.2601213444.to_port": "6556",
"name": "DJukes",
"owner_id": "520150089049",
"revoke_rules_on_delete": "false",
"tags.%": "1",
"tags.Name": "allow-RDP",
"vpc_id": "vpc-8b23ccec"
},
"meta": {
"schema_version": "1"
},
"tainted": false
},
"deposed": [],
"provider": "provider.aws"
}
},
"depends_on": []
}
]
I want to extract public IP addresses to variables using python
"value": [
"34.244.138.72",
"34.249.95.222"
]
So far, i have following code:
#!/bin/python
import json
import os.path
import shutil
from os import mkdir
from pprint import pprint
from python_terraform import *
json_data=open('./terraform.json')
data = json.load(json_data)
json_data.close()
for i in range (0, len (data['modules'])):
print data['modules']['path']['outputs'][1]
And getting following error:
File "./1.py", line 17, in <module>
for i in range (0, len (data['modules']['path']['outputs'])):
TypeError: list indices must be integers, not str
also tried:
for dat in data:
print dat['outputs']
We can see from your JSON that modules is a list, which maps to an array with numeric indices, not a dictionary. (Though, there seems to be only one item in the list.)
So you need to iterate over it with i.
See what you are actually receiving with something like:
for i in range (0, len (data['modules'])):
pprint(data['modules'][i]['outputs']['id']['value'])
Which outputs:
$ python 1.py
[u'34.244.138.72', u'34.249.95.222']

Resources