JSONPath: Difference between revisions

From Planfix
Jump to: navigation, search
No edit summary
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Email rules: Extracting data | Emails sent to Planfix can be parsed]] using JSON. JavaScript Object Notation is a format for storing and exchanging information available as human-readable text.  There are two main elements in a JSON object: the key and the value.
{{#seo:
 
|title=JSONPath
==Example==
|titlemode=append
{"city":"New York", "country":"United States"}
|keywords=planfix, rules, email, extracting data from an email, JSONPath, JSON, json
|description=JSONPath
}}
<div style="background-color:#ffcaca; border: 1px solid #fd9292;padding:10px;">Use the dedicated online service to debug and fix parsing errors: [https://jsonpath.com/ JSONPath Online Evaluator]</div>
 
You can parse incoming [[Email rules: Extracting data|emails]] or [[Incoming webhooks|webhooks]] in Planfix with JSON. [[Email rules: Extracting data | Emails sent to Planfix can be parsed]] using JSON. JavaScript Object Notation is a format for storing and exchanging information available as human-readable text.  There are two main elements in a JSON object: the key and the value.
 
Example:
 
{"city":"New York", "country":"United States"}
*keys — city and country;
*keys — city and country;
*values — New York and United States
*values — New York and United States


Planfix can parse emails in this format and add the relevant data to [[infoblocks]].  
Planfix can parse emails in this format and add the necessary data into info blocks using the  [https://github.com/json-path/JsonPath JsonPath library].
The JsonPath library is used to do so.
Note: If you use a function when parsing, make sure that you insert parenthesis at the end, otherwise the function will not work.
 
https://s.pfx.so/pf/YE/H5gE8u.jpg
==Example №1==
===Sending an Email with JSON Format to Planfix===
*As an example, we'll use the following JSON:
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;border-radius:4px;">
{
<p style="padding-left:10px;">
"firstName": "Denis",<br>
"lastName": "Evans",
</p>
<p style="padding-left:10px;">"address": {</p>
<p style="padding-left:20px;">
"streetAddress": "1109 SW 12th St",<br>
"city": "Newport",<br>
"postalCode": 97365<br>
</p>
<p style="padding-left:10px;"> },</p>
<p style="padding-left:10px;">"phoneNumbers": [</p>
<p style="padding-left:20px;">"1-211-906-4147"<br>
</p>
<p style="padding-left:10px;">]</p>
<p>}</p>
</div>
 
*Let's say we need the following data from the JSON:
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;border-radius:4px;">
{
<p style="padding-left:10px;">
"<span style="color:red;">firstName</span>": "Denis",<br>
"lastName": "Evans",
</p>
<p style="padding-left:10px;">"<span style="color:red;">address</span>": {</p>
<p style="padding-left:20px;">
"streetAddress": "1109 SW 12th St",<br>
"<span style="color:red;">city</span>": "Newport",<br>
"postalCode": 97365<br>
</p>
<p style="padding-left:10px;"> },</p>
<p style="padding-left:10px;">"<span style="color:red;">phoneNumbers</span>": [</p>
<p style="padding-left:20px;">"1-211-906-4147"<br>
<p>}</p>
</div>
 
 
*We would configure the following rule for processing emails:


https://s.pfx.so/pf/vt/BGQzWr.jpg


==Example==
*Next, we create a new customer using the template, indicate which infoblocks to set from which fields, and add the contact to the task created from the email:
An email is sent to Planfix with JSON:
 
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;">
https://s.pfx.so/pf/nG/dL1P6b.jpg
 
*As a result, the necessary data from the email in JSON format was transferred to Planfix:
 
https://s.pfx.so/pf/xN/NtRliu.jpg
 
==Example №2==
===Adding JSON parameters to Planfix data tags=== 
 
For this example, we'll use JSON from a product order in an online store. The data required for adding analytics is highlighted in red:
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;border-radius:4px;">
{<br>
<p style="padding-left:10px;">
"site": "mysite.shop",<br>
"name": "Denis Evans",<br>
"id": "6598634",<br>
"<span style="color:red;">date</span>": "30.11.2024 09:16:05",<br>
"status": "In progress",<br>
"email": "techT7@gmail.com",<br>
"phone": "+1 211 906-4147",<br>
"address": "1109 SW 12th St1",<br>
"price_total": "466.45",<br>
"item_order": [
</p>
<p style="padding-left:10px;">{</p>
<p style="padding-left:20px;">
"sku": "598623",<br>
"<span style="color:red;">name</span>": Cobalt drill bit set 29pc",<br>
"barcode": "596325689126",<br>
"<span style="color:red;">price</span>": "29.99",<br>
"<span style="color:red;">quantity</span>": 5
</p>
<p style="padding-left:10px;">
},<br>
{
{
"firstName": "John",
</p>
"lastName": "Smith",
<p style="padding-left:20px;">
"address": {
"sku": "589624",<br>
"streetAddress": "10 Main Street, Apartment 101",
"name": "High torque driver",<br>
"city": "Pleasantville",
"barcode": "5963256858963",<br>
"postalCode": 10101
"price": "230.00",<br>
},
"quantity": 1
"phoneNumbers": [
</p>
"812-123-1234",
<p style="padding-left:10px;">
"916-123-4567"
},<br>
]
{
}</div>
</p>
<p style="padding-left:20px;">
"sku": "579824",<br>
"name": "Half inch ratchet 120 tooth",<br>
"barcode": "5963256889634",<br>
"price": "43.25",<br>
"quantity": 2
</p>
<p style="padding-left:10px;">
}<br>
]</p>
}<br>
</div>
 
*Setting up a separate rule for email tasks. Parsing JSON:
 
https://s.pfx.so/pf/V3/4bwSgN.jpg
 
*Create a new task and notify the required employee of its creation:


 
https://s.pfx.so/pf/0H/KxwRR2.jpg
 
*Adding data tags to the created task. Note: It's important to specify the parameter '''Add as many lines as there are values in the infoblock''' to ensure that all values are added to the data tags.


Let's say we need the following data from the JSON:
https://s.pfx.so/pf/s8/k56IP5.jpg
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;">
{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "10 Main Street, Apartment 101",
"city": "Pleasantville",
"postalCode": 10101
},
"phoneNumbers": [
"812-123-1234",
"916-123-4567"
]
}</div>
 


We would configure the following rule for processing emails:
*As a result, the task displays the notification and data tags:


https://s.pfx.so/pf/th/ptZGmD.jpg


https://s.pfx.so/pf/nM/LKfSAe.jpg


== Go To ==
== Go To ==

Latest revision as of 12:10, 2 December 2024

Use the dedicated online service to debug and fix parsing errors: JSONPath Online Evaluator

You can parse incoming emails or webhooks in Planfix with JSON. Emails sent to Planfix can be parsed using JSON. JavaScript Object Notation is a format for storing and exchanging information available as human-readable text.  There are two main elements in a JSON object: the key and the value.

Example:

{"city":"New York", "country":"United States"}
  • keys — city and country;
  • values — New York and United States

Planfix can parse emails in this format and add the necessary data into info blocks using the JsonPath library. Note: If you use a function when parsing, make sure that you insert parenthesis at the end, otherwise the function will not work.

H5gE8u.jpg

Example №1

Sending an Email with JSON Format to Planfix

  • As an example, we'll use the following JSON:

{

"firstName": "Denis",
"lastName": "Evans",

"address": {

"streetAddress": "1109 SW 12th St",
"city": "Newport",
"postalCode": 97365

},

"phoneNumbers": [

"1-211-906-4147"

]

}

  • Let's say we need the following data from the JSON:

{

"firstName": "Denis",
"lastName": "Evans",

"address": {

"streetAddress": "1109 SW 12th St",
"city": "Newport",
"postalCode": 97365

},

"phoneNumbers": [

"1-211-906-4147"

}

 

  • We would configure the following rule for processing emails:

BGQzWr.jpg

  • Next, we create a new customer using the template, indicate which infoblocks to set from which fields, and add the contact to the task created from the email:

dL1P6b.jpg

  • As a result, the necessary data from the email in JSON format was transferred to Planfix:

NtRliu.jpg

Example №2

Adding JSON parameters to Planfix data tags

For this example, we'll use JSON from a product order in an online store. The data required for adding analytics is highlighted in red:

{

"site": "mysite.shop",
"name": "Denis Evans",
"id": "6598634",
"date": "30.11.2024 09:16:05",
"status": "In progress",
"email": "techT7@gmail.com",
"phone": "+1 211 906-4147",
"address": "1109 SW 12th St1",
"price_total": "466.45",
"item_order": [

{

"sku": "598623",
"name": Cobalt drill bit set 29pc",
"barcode": "596325689126",
"price": "29.99",
"quantity": 5

},
{

"sku": "589624",
"name": "High torque driver",
"barcode": "5963256858963",
"price": "230.00",
"quantity": 1

},
{

"sku": "579824",
"name": "Half inch ratchet 120 tooth",
"barcode": "5963256889634",
"price": "43.25",
"quantity": 2

}
]

}

  • Setting up a separate rule for email tasks. Parsing JSON:

4bwSgN.jpg

  • Create a new task and notify the required employee of its creation:

KxwRR2.jpg

  • Adding data tags to the created task. Note: It's important to specify the parameter Add as many lines as there are values in the infoblock to ensure that all values are added to the data tags.

k56IP5.jpg

  • As a result, the task displays the notification and data tags:

ptZGmD.jpg

LKfSAe.jpg

Go To