papal plus malformed_request JSON with shipping address - json

To show the Paypal plus iFrame (REST API) i make a Request with JSON
{
"intent": "sale",
"experience_profile_id": "XP-XXXX-XXXX-XXX-XXX",
"redirect_urls": {
"return_url": "https://www.XXXXXXX.de/bestellen.php",
"cancel_url": "https://www.XXXXXXX.de/zahlungabbruch.php"
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "53.45",
"currency": "EUR",
"details": {
"subtotal": "49.5",
"shipping": "3.95"
}
},
"description": "Tollewolle",
"invoice_number": "",
"item_list": {
"items": [
{
"quantity": "4",
"name": "Fine Kid - 50",
"price": "8.25",
"currency": "EUR",
"sku": "8-50"
},
{
"quantity": "2",
"name": "Fine Kid - 208",
"price": "8.25",
"currency": "EUR",
"sku": "8-208"
}
]
},
"shipping_address": {
"line1": "Rechnungs Str. 41",
"city": "Flensburg",
"postal_code": "24939",
"country_code": "DE"
}
}]
}
Without the shipping_address it works fine.
With the address i get an Error 'MALFORMED_REQUEST'

I believe Shipping address is a child ob lineitems so you need to move it up a level. E.g.
"transactions": [{"amount": {"total": "53.45", "currency":
"EUR","details":{"subtotal": "49.5", "shipping":
"3.95"}},"description": "Tollewolle", "invoice_number": "",
"item_list": {"items": [{"quantity": "4", "name": "Fine Kid - 50",
"price": "8.25", "currency": "EUR", "sku": "8-50"},{"quantity": "2",
"name": "Fine Kid - 208","price": "8.25", "currency": "EUR", "sku":
"8-208"}],"shipping_address": {"line1": "Rechnungs Str. 41","city":
"Flensburg", "postal_code": "24939", "country_code": "DE"}}}]

Related

Moving a JSON array which have another array elements to the same LEVEL

I have the following JSON which have an element array_within_array in another array. So I want to pull both array_within_array element and upper array element(event_array) to root level using jq.
So here there are 3 events.
meal_selection
login
placed_order
Event placed_order have two sub-events in array. So after conversion there should be 4 events(1 from meal_selection, 1 from login and 2 from placed_order). these all should be on the same level.
Here is the JSON
{
"region": "USA",
"user_id": "123",
"event_array": [{
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "meal_selection",
"created_at": "2021-08-13 01:28:57"
},
{
"event_name": "login",
"created_at": "2021-08-13 01:29:02"
},
{
"event_attributes": {
"array_within_array": [
{
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
{
"date": "2021-08-18",
"category": "dinner",
"location": "home"
}
]
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
]
}
and I want to convert to the below one
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "meal_selection",
"created_at": "2021-08-13 01:28:57"
}
{
"region": "USA",
"user_id": "123",
"event_name": "login",
"created_at": "2021-08-13 01:29:02"
}
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-18",
"category": "dinner",
"location": "home"
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
Here's a straightforward solution that keeps things simple by using two steps:
{ region, user_id} + (.event_array[] )
| if .event_attributes|has("array_within_array")
then .event_attributes.array_within_array as $a
| .event_attributes = $a[]
else .
end

Parsing JSON with VBA-Web and VBA JSON Parser

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"
}
]
}
}```

Error parsing a specific JSON file in Snowflake with File Format

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

Extract Specific Values in a JSON String using XSLT

I need help in getting the specific keys and its dynamic values stored in JSON string in an XML element.
Below is an example of the JSON data:
<data attribute-id="item">
[
{
"item_name": "item1",
"quantity": 1,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 34.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
},
"price": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
},
{
"item_name": "item2",
"quantity": 2,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 14343.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 3431.5,
"label": "640.177,50 CAD",
"base": {
"amount": 181.5,
"currency": "USD",
"label": "US$181.50"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 753150,
"label": "753.150,00 CAD",
"base": {
"amount": 213.52,
"currency": "USD",
"label": "US$213.52"
}
},
"price": {
"currency": "CAD",
"amount": 376575,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -112972.5,
"label": "-112.972,50 CAD",
"base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
}
]
</data>
My Expected output is to get key "item_name" and its dynamic value and key "amount" and its dynamic value (key->discount (base array)). Below is the expected output from the given JSON string:
"item_name": "item1","base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
},
"item_name": "item2","base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
Any help is greatly appreciated!

Custom JSON format webhook WooCommerce Wordpress

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
}