I am trying to post a blog to Wordpress. However, the Wordpress node wasn’t working so I am using the HTTP Request node as a workaround. I seem to be close but I just cannot get it to work. Here is the workflow:
{
“nodes”: [
{
“parameters”: {
“rule”: {
“interval”: [
{
“field”: “months”,
“triggerAtDayOfMonth”: 21,
“triggerAtHour”: 13,
“triggerAtMinute”: 30
}
]
}
},
“type”: “n8n-nodes-base.scheduleTrigger”,
“typeVersion”: 1.2,
“position”: [
0,
0
],
“id”: “ae29a20d-89a7-4969-a253-7d3342a892cf”,
“name”: “Schedule Trigger”
},
{
“parameters”: {
“modelId”: {
“__rl”: true,
“value”: “gpt-4”,
“mode”: “list”,
“cachedResultName”: “GPT-4”
},
“messages”: {
“values”: [
{
“content”: “Write a 900-word blog post on a seasonally, culturally relevant dog topic for Canadian pet owners. Suggest a suitable blog title and a short summary. Format your response as:\nTitle: \nSummary:
Here is the input to the HTTP Request node:
[
{
“Title”: “=$("OpenAI").item.json.choices[0].message.content.match(/Title:\s*(.?)\n\n/)[1]",
“Summary”: "=$("OpenAI").item.json.choices[0].message.content.match(/Summary:\s(.?)\n\n/)[1]",
“Content”: "=$("OpenAI").item.json.choices[0].message.content.match(/Content:\s([\s\S]*)/)[1]”
}
]
Sorry, I should’ve been more clear in my question. What is the actual resulting json after the templating receive all the values and right before this JSON is sent to the HTTP Request node.
If I understand correctly, here is the resulting JSON from the OpenAI node before it goes into the Edit Fields node and then the HTTP Request node.
[
{
“index”: 0,
“message”: {
“role”: “assistant”,
“content”: “Title: Winter Woofs: Caring for Your Canine in the Frosty Canadian Winter\n\nSummary: This blog post tackles the unique challenges Canadian pet owners face in the frosty winter months. From bracing the cold to dealing with ice and snow, we cover everything you need to know to keep your pet comfortable, safe and healthy during winter.\n\nContent: \n\nAs the season’s first flurries touch the ground, the landscape transforms into a perpetual winter wonderland perfect for dogs to frolic in and owners to appreciate. However, the freezing temperatures, ice, slush, and snow that characterize Canadian winters can be tough on our furry friends. With the right tips and strategies, though, you can help your pooch sail smoothly through the winter months. \n\nThe first matter of importance that winter brings is the long-held controversy: Do dogs need coats? The answer is, it depends. Breeds with thick coats such as Huskies and Malamutes are built for winter climates, but those with short or thin coats like Greyhounds or Chihuahuas may struggle with the cold. If your pet doesn’t have a naturally thick coat, consider getting them a winter sweater or jacket. Dogs should also have their paws protected from the cold and the potentially harmful substances used for ice melting. Dog boots can keep their paws warm and free from nicks and cuts, but if your pet completely refuses to don any footwear, consider using a paw balm or wax. \n\nJust as salt can form a protective layer on roads and sidewalks, it can also pose a threat to our four-legged friends. Chemical de-icers can irritate and damage your pet’s paws or cause stomachs problems if ingested. Always wash your dog’s feet after a walk or use pet-friendly ice melts. Owners should also be wary of antifreeze leaks from cars which can be lethal to animals even in small amounts. \n\nRemember, in cold weather it’s easy for dogs to get dehydrated so always provide fresh water. If your home is unusually dry, consider a pet-friendly humidifier to avoid dry skin. \n\nOutdoor play during winters is fun but its also essential to consider visibility. With reduced daylight in winter months, reflective gear becomes a must-have for evening walks. Illuminated collars or vests can ensure your pet is seen and safe during those frosty evenings.\n\nWhile the rules of basic dog nutrition remain the same in winter, it’s important to note that dogs may require extra calories in the cold season as they burn more energy trying to keep warm. Always consult your vet before changing your dog’s diet. \n\nDon’t forget that your dog can still get a workout indoors, even when the weather outside is forbidding. Indoor puzzle toys, treadmills, and a good old-fashioned game of fetch can keep your dog active and fit. \n\nJust like humans, dogs are also susceptible to hypothermia and frostbite. Learn the symptoms and seek veterinary care if you suspect your pet is affected. Some of the common signs are paleness, shivering, lethargy and ice formation on the body.\n\nLast but not least, remember the stray animals often suffer the worst during brutal winters. Consider setting up a small shelter or leaving out food and fresh water for stray dogs and cats in your area.\n\nAs a dog owner, we know that your top priority is your pet’s welfare. While winter comes with its challenges, remember that a combination of preparation and vigilance can ensure your dog remains healthy, active and happy in the frostiest season in Canada. \n\nDon’t forget that winters also bring an array of unique activities that you and your dog can enjoy together. Whether it is a simple walk in the winter wonderland, a lighthearted snowball fight, or snuggling with your pooch near the fireplace, the possibilities are endless. \n\nWinters in Canada might be long and cold, but they also allow usual experiences and moments that create unforgettable memories with our beloved pets. After all, even in the frostiest of days, a Canadian winter can be their wonderland too. So stay warm, keep safe and enjoy the season with your winter woof!”,
“refusal”: null,
“annotations”:
},
“logprobs”: null,
“finish_reason”: “stop”
}
]
ok, let’s see if we can stick this together. In the http request node I see that you are trying to send the above json.
First I would try to make it one line (not sure if the new lines are just a result of the paste of your workflow to the community forum or it is actually how your json text looks like in n8n.
Secondly, it references the values like $json.Title and $json.Content. Where do these come from and what their values are (or what would help even better - what is the value of the entire $json). I don’t believe it expands into the json you provided, because I don’t see the Title key in it, and the content is inside message and is lowercase.
And finally, what I was actually asking is how does this json body looks like after all the values are populated. You can execute nodes before http request and then click into a field and in http request node, it should pre-render the json for you.
Unless I awfully misunderstood you, then please correct me.
Here is the new JSON all on one line in the HTTP Request node:
{“title”:“={{ $json.Title }}”,“content”:“={{ $json.Content }}”,“status”:“publish”}
Here is the result from the above JSON which indicates where $json.Title and $json.Content pull from:
{“title”:“==$(“OpenAI”).item.json.choices[0].message.content.match(/Title:\s*(.?)\n\n/)[1]“,“content”:”==$(“OpenAI”).item.json.choices[0].message.content.match(/Content:\s([\s\S]*)/)[1]”,“status”:“publish”}
Yep. I opened the nodes and confirmed the credentials are linked to mine. Still getting the error. This is what I have been dealing with for the past couple of days. I seem to just be going in circles - credential errors, JSON errors
Did you use the App password in the credentials or the user password which you use to login to the admin panel? You should be using the Application Passwords from the user profile at /wp-admin/profile.php