@Dan_Burykin , thanks for adding more clarity. If you do not mind, let me extend it even further with more details as it is important for understanding of what you are trying to achieve and how that could be completed.
For that, let’s first concentrate on item 1 as it is what you started with and added item 2 later on. The item 1 does not require item 2 - they are separate topics although related.
Item 1: Send array of emails with variables
Send to API array of emails I get from the same previous API call and their variables taken from same and another API
When checking your workflow I have concluded the following:
- “Aries” node: this is in fact the call to the chatbot which provides horoscope for the people born on a specific date.
- “HTTP Request1” node makes an API call to Get all of the contacts in a mailing list by variable.
- “HTTP Request2” node updates the address book as per Add emails to a mailing list (single-opt-in)
According to the API description related the last node, the address book could be updated with email addresses in two forms: with and without variables. Adding email addresses without variables was touched by me to some degree. What is needed is the array of emaul addresses only as in
{
"emails":["[email protected]", "[email protected]"]
}
However, you seem to require the emails with variables in which case the POSTed data is in the form
{
"emails":[
{
"email":"[email protected]",
"variables":{
"name":"Elizabeth",
"Phone":"380632727700"
}
},
{
"email":"[email protected]"
}
]
}
I already mentioned that “Aries” node produces a single text - horoscope advice. The “HTTP Request1” essentially node gives you email addresses:
[
{
"email": "[email protected]",
"status": 0,
"status_explain": "New"
},
{
"email": "[email protected]",
"status": 1,
"status_explain": "Active"
}
]
You did mention you make another chatbot request which presumably provides another set of variables as in
[
{
"email": "[email protected]",
"phone": null,
"add_date": "2024-08-01 13:10:29",
"status": 1,
"status_explain": "Active",
"variables": {
"Timer 0…23 ET": "0",
"Sign": "Pisces"
}
},
{
"email": "[email protected]",
"phone": null,
"add_date": "2024-07-30 00:02:52",
"status": 8,
"status_explain": "In blacklist",
"variables": {
"Name": "[email protected]",
"Timer 0…23 ET": 11,
"Sign": "Capricorn",
"Prediction": "…",
"Prediction date": "…"
}
}
]
This request is not depicted in your workflow. Thus, I would have to make some further assumptions here as well. I assume that your workflow(s) use either the horoscope text as a variable (presumably prediction with the prediction date) or the data from the “missing” chatbot node as a variable but not both at the same time for the same email address.
I am going to narrow down the requirement further to make sure we are not mixing up different issues. Here’s my revised solution to the item 1. As a reminder, the endpoint (“HTTP Request2” node) accepts the data in the format
{
"emails":[
{
"email":"[email protected]",
"variables":{
"variable 1": "value 1",
"variable 2": "value 2"
}
},
{
"email":"[email protected]"
}
]
}
As we are dealing with the 1st chatbot, the variables would be “Prediction” (aka horoscope text) and “Prediction date” (date given to the chatbot).
Here’s the revised solution
I left the node names unchanged so that you could correlate them with your own workflow you shared. The JSON POSTed in the last node now has the expression
{{
{ "emails": $json.emails }
}}
which translates into JSON POSTed to the API in the form
{
"emails": [
{
"email": "[email protected]",
"variables": {
"Prediction": "Some text",
"Prediction date": "August 2, 2024"
}
},
{
"email": "[email protected]",
"variables": {
"Prediction": "Some text",
"Prediction date": "August 2, 2024"
}
}
]
}
Hopefully I got it right this time.