Need help on parsing JSON data using VBA-Web tool (https://github.com/VBA-tools/VBA-Web) & VBA-JSON Converter
Here is my sample code that I am able to pull the order using the get method but I stumped on parsing the JSON to get the key, value pair that I want
Sub TestWC()
Dim WoocommerceClient As New WebClient
Dim Client As String
Dim Secret As String
WoocommerceClient.BaseUrl = "https://www.example.com"
Client = "ck"
Secret = "cs"
Dim Request As New WebRequest
Request.Method = Httpget
Request.AddQuerystringParam "consumer_key", Client
Request.AddQuerystringParam "consumer_secret", Secret
Dim Response As WebResponse
Request.Resource = "/wp-json/wc/v3/orders"
Set Response = WoocommerceClient.Execute(Request)
//Response.Data -> Should be equal to the JSON data
Dim test As Object
Set test = JsonConverter.ParseJson(Response.Data)
End Sub
When I run this code it will have a error popup saying object required 424 . I also did another work around where I put into the first cell the whole JSON Data using Sheet1.Range("A1").Value = Response.Content then by pulling the data from the cell into the function
Set test = JsonConverter.ParseJson(Sheet1.Range("A1").Value)
I still get the object required error, here is a Sample JSON format from Woocommerce REST API
"id": 727,
"parent_id": 0,
"number": "727",
"order_key": "wc_order_58d2d042d1d",
"created_via": "rest-api",
"version": "3.0.0",
"status": "processing",
"currency": "USD",
"date_created": "2017-03-22T16:28:02",
"date_created_gmt": "2017-03-22T19:28:02",
"date_modified": "2017-03-22T16:28:08",
"date_modified_gmt": "2017-03-22T19:28:08",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "10.00",
"shipping_tax": "0.00",
"cart_tax": "1.35",
"total": "29.35",
"total_tax": "1.35",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe#example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"company": "",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"transaction_id": "",
"date_paid": "2017-03-22T16:28:08",
"date_paid_gmt": "2017-03-22T19:28:08",
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [
{
"id": 13106,
"key": "_download_permissions_granted",
"value": "yes"
}
],
"line_items": [
{
"id": 315,
"name": "Woo Single #1",
"product_id": 93,
"variation_id": 0,
"quantity": 2,
"tax_class": "",
"subtotal": "6.00",
"subtotal_tax": "0.45",
"total": "6.00",
"total_tax": "0.45",
"taxes": [
{
"id": 75,
"total": "0.45",
"subtotal": "0.45"
}
],
"meta_data": [],
"sku": "",
"price": 3
},
{
"id": 316,
"name": "Ship Your Idea – Color: Black, Size: M Test",
"product_id": 22,
"variation_id": 23,
"quantity": 1,
"tax_class": "",
"subtotal": "12.00",
"subtotal_tax": "0.90",
"total": "12.00",
"total_tax": "0.90",
"taxes": [
{
"id": 75,
"total": "0.9",
"subtotal": "0.9"
}
],
"meta_data": [
{
"id": 2095,
"key": "pa_color",
"value": "black"
},
{
"id": 2096,
"key": "size",
"value": "M Test"
}
],
"sku": "Bar3",
"price": 12
}
],
"tax_lines": [
{
"id": 318,
"rate_code": "US-CA-STATE TAX",
"rate_id": 75,
"label": "State Tax",
"compound": false,
"tax_total": "1.35",
"shipping_tax_total": "0.00",
"meta_data": []
}
],
"shipping_lines": [
{
"id": 317,
"method_title": "Flat Rate",
"method_id": "flat_rate",
"total": "10.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": []
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v3/orders/727"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v3/orders"
}
]
}
}```
Related
I have created a Stage and File Format in Snowflake which works with all my other JSON files except this, which throws an error:
Error parsing JSON: misplaced { File 'rooms.json.gz', line 1,
character 2 Row 0, column $1
I am using the same query that I am using for other files.
SELECT $1
FROM #MySchema.MY_STAGE/rooms.json.gz
;
What is wrong with the structure of this specific JSON file?
{
"rooms": [
{
"area": 131.49,
"longDescription": "",
"dateCreated": 1589908063390,
"reservable": false,
"name": "E249",
"remoteInfo": "",
"description": "",
"id": 2,
"type": {
"hexColor": "c16058",
"contentFlag": 1,
"cost": 0.0,
"dateCreated": 1308610520717,
"color": {},
"name": "BREAK ROOM",
"occupiable": false,
"id": 120,
"parkingSpace": false,
"dateUpdated": 1591818585913,
"typeCode": ""
},
"floor": {
"area": 25312.9878,
"dateCreated": 1589907703870,
"drawingAvailable": true,
"interiorGross": 0.0,
"name": "2",
"leaseArea": 0.0,
"id": 12,
"building": {
"address": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"city": "Some City",
"street": "Some Drive",
"postalCode": "00000",
"state": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"defaultSelected": false,
"code": "XX",
"name": "Some State",
"id": 66,
"categoryName": "state"
}
},
"code": "B2",
"dateCreated": 1589907508020,
"metric": false,
"name": "Some name",
"location": {},
"revitLink": "",
"id": 45,
"dateUpdated": 1601315841453,
"costCenters": []
},
"dateUpdated": 1600441936663
},
"capacity": 0,
"dateUpdated": 1600441936960
}
]
}
Edit: Screenshot from Notepad++ with all characters enabled
I need to import some JSON data am getting into my database. I'd like to use PowerShell and figured out a little, but I need help getting the final piece together.
How to convert following nested JSON to flat CSV in Powershell?
Following is the JSON data :
$openings = '{"objects": [
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
},
{
"id": 136691,
"title": "UX Desginer",
"description": "Hiring a UX Designer for our Front End Team",
"position_type": "full_time",
"is_remote_allowed": false,
"is_archived": false,
"is_private": false,
"state": "Draft",
"location": {
"city": "Bangalore",
"state": "Karnataka",
"zipcode": "560078",
"country": "India"
},
"team": "Front-end Team",
"created_date": 1472804002,
"modified_date": 1472804018,
"application_email": "recruiterbox-dmcc0616#applications.recruiterbox.com",
"hosted_url": "https://recruiterbox.recruiterbox.com/jobs/d933h5yh"
}
],
"meta": {
"total": 1,
"limit": 20,
"offset": 0
}}'
To be clear upfront, I'm not a professional - just trying to get a task done and I have minimal expertise. What I thought would be easy is apparently not so. I've dealt with APIs and XML but it's always been me initiating. This is apparently different.
Goal:
Receive HTTP POST Webhook data (JSON) from my Wordpress/Woocommerce website.
Problem:
The Webhook is working and being received perfectly by RequestBin.The JSON string is being sent over HTTP. But I'm not even sure the request is being heard by my CF Template. When I try to write the received data into a session variable so I can at least see it, nothing is there?!?! How do I find out if my code being triggered?
First line of code in my CF Template:
<cfset HTTPRequestData = deserializeJSON(ToString(getHTTPRequestData().content))>
Example from RequestBin of data being sent:
{
"id": 259609,
"parent_id": 0,
"number": "CW-104-270219",
"order_key": "xxxxxxxxxxxx",
"created_via": "checkout",
"version": "3.5.5",
"status": "completed",
"currency": "USD",
"date_created": "2019-02-27T15:11:58",
"date_created_gmt": "2019-02-27T20:11:58",
"date_modified": "2019-02-27T15:11:59",
"date_modified_gmt": "2019-02-27T20:11:59",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "9.68",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 2,
"customer_ip_address": "xxxxxxxxxxxx",
"customer_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
"customer_note": "",
"billing": {
"first_name": "Valerie",
"last_name": "Criswell",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "xxxxxxxxxx",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "authorize_net_aim",
"payment_method_title": "Credit Card",
"transaction_id": "xxxxxxxxxxxxx",
"date_paid": "2019-02-27T15:11:59",
"date_paid_gmt": "2019-02-27T20:11:59",
"date_completed": "2019-02-27T15:11:59",
"date_completed_gmt": "2019-02-27T20:11:59",
"cart_hash": "xxxxxxxxxxxxx",
"meta_data": [
{
"id": 8785641,
"key": "_wcson_order_number",
"value": "CWD-259609-022719-108"
},
{
"id": 8785642,
"key": "_order_number",
"value": "104"
},
{
"id": 8785643,
"key": "_order_number_formatted",
"value": "CW-104-270219"
},
{
"id": 8785644,
"key": "_order_number_meta",
"value": {
"prefix": "CW-",
"suffix": "-{DD}{MM}{YY}",
"length": "2"
}
},
{
"id": 8785645,
"key": "_wc_authorize_net_aim_retry_count",
"value": "0"
},
{
"id": 8785646,
"key": "_wc_authorize_net_aim_trans_id",
"value": "xxxxxxxx"
},
{
"id": 8785647,
"key": "_wc_authorize_net_aim_trans_date",
"value": "2019-02-27 15:11:59"
},
{
"id": 8785648,
"key": "_wc_authorize_net_aim_environment",
"value": "production"
},
{
"id": 8785649,
"key": "_wc_authorize_net_aim_account_four",
"value": "xxxxxxxx"
},
{
"id": 8785650,
"key": "_wc_authorize_net_aim_authorization_amount",
"value": "xxxxxxx"
},
{
"id": 8785651,
"key": "_wc_authorize_net_aim_authorization_code",
"value": "xxxxxxx"
},
{
"id": 8785652,
"key": "_wc_authorize_net_aim_charge_captured",
"value": "yes"
},
{
"id": 8785653,
"key": "_wc_authorize_net_aim_card_expiry_date",
"value": "21-08"
},
{
"id": 8785654,
"key": "_wc_authorize_net_aim_card_type",
"value": "mastercard"
},
{
"id": 8785659,
"key": "_pip_invoice_number",
"value": "CW-104-270219"
},
{
"id": 8785660,
"key": "_wc_pip_invoice_email_count",
"value": "1"
},
{
"id": 8785661,
"key": "_wc_pip_packing_list_email_count",
"value": "1"
}
],
"line_items": [
{
"id": 17,
"name": "I Give Myself Away - MP3 Download - 30 Day Access",
"product_id": 192127,
"variation_id": 192128,
"quantity": 1,
"tax_class": "",
"subtotal": "9.68",
"subtotal_tax": "0.00",
"total": "9.68",
"total_tax": "0.00",
"taxes": [],
"meta_data": [
{
"id": 182,
"key": "pa_format",
"value": "download-30-day"
}
],
"sku": "131599-DL30DAY",
"price": 9.68
}
],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": []
}
Let's start with the stated goal:
Receive HTTP POST Webhook data from my Wordpress/Woocommerce website.
Can your Wordpress site hit the intended URL on your ColdFusion site? If so, can you record / dump the HTTP POST request to a file?
<cfdump var="#form#" format="html" output="/full/path/to/file">
This will tell you if you're even receiving the request correctly.
I want my Woocommerce store connected to a shipping parcel company. There is no existing WooCommerce plugin for it. I want to do it with webhooks, I had already successfully made a POST request to a URL after the order.created action. The JSON output contains all the shipping information. But I want to change the format of the JSON output.
The current JSON output is something like this.
{
"id": 605,
"parent_id": 0,
"status": "pending",
"order_key": "wc_order_5893614a8fb78",
"number": 605,
"currency": "USD",
"version": "2.6.13",
"prices_include_tax": false,
"date_created": "2017-02-02T16:41:46",
"date_modified": "2017-02-02T16:41:46",
"customer_id": 2,
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "13.60",
"shipping_tax": "1.22",
"cart_tax": "1.44",
"total": "32.24",
"total_tax": "2.66",
"billing": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257 ",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US",
"email": "daman#singhdd.com",
"phone": "(122) 274-5555"
},
"shipping": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US"
},
"payment_method": "paypal_express",
"payment_method_title": "Paypal Express",
"transaction_id": "",
"customer_ip_address": "103.41.36.35",
"customer_user_agent": "PostmanRuntime/3.0.9",
"created_via": "rest-api",
"customer_note": "",
"date_completed": "2017-02-02T08:41:46",
"date_paid": "",
"cart_hash": "",
"line_items": [
{
"id": 79,
"name": "Kaju Katli",
"sku": "SW-282",
"product_id": 491,
"variation_id": 494,
"quantity": 1,
"tax_class": "",
"price": "15.98",
"subtotal": "15.98",
"subtotal_tax": "1.44",
"total": "15.98",
"total_tax": "1.44",
"taxes": [
{
"id": 1,
"total": 1.4382,
"subtotal": 1.4382
}
],
"meta": [
{
"key": "packing-size",
"label": "Packing Size",
"value": "2lb Box"
}
]
}
],
"tax_lines": [
{
"id": 81,
"rate_code": "SALES TAX-1",
"rate_id": "1",
"label": "Sales Tax",
"compound": false,
"tax_total": "1.44",
"shipping_tax_total": "1.22"
}
],
"shipping_lines": [
{
"id": 80,
"method_title": "USPS Medium Flat Rate Box",
"method_id": "usps_medium_box",
"total": "13.60",
"total_tax": "0.00",
"taxes": []
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders/605"
}
],
"collection": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders"
}
],
"customer": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/customers/2"
}
]
}
}
The JSON output should be something like this.
{
"name": "Gijs Boersma",
"street": "Lange laan",
"house_number": "29",
"house_number_extension": "a",
"zipcode": "9281EM",
"city": "Zevenaar",
"telephone": "0602938172",
"email": "noreply#example.com",
"reference": "Bestelling 112",
"pick_up_point": {
"uuid": "560db083-d941-425b-b3b6-b813718297e1"
},
"product": "sameday_parcel_medium",
"product_options": [
{
"option": "allow_neighbours",
"value": false
},
{
"option": "require_signature",
"value": false
},
{
"option": "age_check_18",
"value": false
},
{
"option": "perishable",
"value": true,
"max_attempts": 2
}
]
}
you can do this by the orders filter.
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'change_shop_order_response', 10, 3 );
function change_shop_order_response( $response, $item, $request ) {
//Do your stuff here with the $response object.
return $response
}
I have the following JSON that I am looking to convert into a GridView. I have been able to successfully do this for a portion of the JSON. It seems to fail on the deposit and withdrawals section. Anyone have any suggestions?
{
"results": [
{
"id": "51142254",
"tp_id": "!XP4D49X0CD123628",
"firstname": "Owner",
"lastname": "Operator",
"email": "",
"phone": "",
"enrolled": "1",
"balance": 247.54,
"fleet": "Test Express",
"deposits": [
{
"id": "184022380",
"date": "2016-02-17",
"amount": "200.00",
"transID": "135246",
"memo": "Scheduled Deposit",
"status": "Cleared"
},
{
"id": "184022383",
"date": "2016-02-25",
"amount": "200.00",
"transID": "246357",
"memo": "Scheduled Deposit",
"status": "Cleared"
},
{
"id": "184022386",
"date": "2016-03-02",
"amount": "200.00",
"transID": "975468",
"memo": "Scheduled Deposit",
"status": "Cleared"
}
],
"withdrawals": [
{
"id": "184026949",
"date": "2016-03-09",
"amount": "352.46",
"transID": "395920",
"memo": "Invoice\r\n\r\n100234",
"status": "Cleared"
}
]
},
{
"id": "51142326",
"tp_id": "!XP4D49X7CD123612",
"firstname": "Owner",
"lastname": "Operator",
"email": "",
"phone": "",
"enrolled": "1",
"balance": 0,
"fleet": "Test\r\nExpress",
"deposits": [],
"withdrawals": []
}
]
}
This is the current code I use for GridView.
Dim UserList As List(Of api_Test_Deposit) = JsonConvert.DeserializeObject(Of List(Of api_Test_Deposit))(GetUrlString(searchType, searchValue))
Dim table = JsonConvert.DeserializeObject(Of DataTable)(GetUrlString(searchType, searchValue))
Return table