JSONPath: Difference between revisions
No edit summary  | 
				|||
| (29 intermediate revisions by the same user not shown) | |||
| Line 8: | Line 8: | ||
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.  | 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.  | ||
{"city":"New York", "country":"United States"}  | 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   | 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].  | ||
Note: If you use a function when parsing, make sure that you insert parenthesis at the end, otherwise the function will not work.  | |||
==Example==  | |||
https://s.pfx.so/pf/YE/H5gE8u.jpg  | |||
<div style="background-color:#f9f9f9; border:1px solid #ddd; padding:1em;">  | ==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;">  | |||
{  | {  | ||
"firstName": "  | <p style="padding-left:10px;">  | ||
"lastName": "  | "firstName": "Denis",<br>  | ||
"address": {  | "lastName": "Evans",  | ||
"streetAddress": "  | </p>  | ||
"city": "  | <p style="padding-left:10px;">"address": {</p>  | ||
"postalCode":   | <p style="padding-left:20px;">  | ||
},  | "streetAddress": "1109 SW 12th St",<br>  | ||
"phoneNumbers": [  | "city": "Newport",<br>  | ||
"  | "postalCode": 97365<br>  | ||
"  | </p>  | ||
]  | <p style="padding-left:10px;"> },</p>  | ||
}</div>  | <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  | |||
*  | *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:  | ||
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>  | |||
{  | |||
</p>  | |||
<p style="padding-left:20px;">  | |||
"sku": "589624",<br>  | |||
"name": "High torque driver",<br>  | |||
"barcode": "5963256858963",<br>  | |||
"price": "230.00",<br>  | |||
"quantity": 1  | |||
</p>  | |||
<p style="padding-left:10px;">  | |||
},<br>  | |||
{  | |||
</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/  | 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.  | |||
https://s.pfx.so/pf/  | https://s.pfx.so/pf/s8/k56IP5.jpg  | ||
*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
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.
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:
 
- 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:
 
- As a result, the necessary data from the email in JSON format was transferred to Planfix:
 
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:
 
- Create a new task and notify the required employee of its creation:
 
- 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.
 
- As a result, the task displays the notification and data tags: