Merging data from 2 different structures

FINAL EDIT: I’ve fixed the two issues described below, but am now faced with a final one at the last node, HTTP Request to WP. It says, “The resource you are requesting could not be found.”

I’m wondering if my JSON in the Edit Fields Back to WP node is structured correctly. I’m thinking it might have something to do with the ID field.

ERRORS FIXED:

  1. by removing the opening and closing square brackets in the Edit Fields Back to WP node but I then discovered the merge node is not working correctly.
  2. I changed the Store ID data type in the Edit Fields Gsheet node to String to match the WP data type.

Describe the problem/error/question

The ‘JSON Output’ in item 0 does not contain a valid JSON object

I’m trying to update a custom post type on my WordPress website with Google Sheets data. Everything seems to work** up to the Edit Fields Back to WP node. The assignment of the placeholders appears to work in the result pager in the Edit Fields Back to WP node, but the actual output throws the above error.

In the merge node I’m enriching output 2 and when there is a clash of data I’m preferring input 1. I tested the merge by adding some a’s to the beginning of an email address for a record in Google Sheets.

Store ID Business Name Phone Email Date Created F address
1188 5 Star Custom Portable Buildings (205) 339-3518 aaaaa[email protected] 11/03/2022 12:28:19 PM 6602 McFarland Blvd, Northport, Alabama, 35476

The last record in the JSON output of the Merge node does not reflect that change. Here’s the last page of that output:

[
{
"Store ID2": 
"158",
"Business Name": 
"BackYard Essentials",
"Phone": 
"478-954-5598",
"Email": 
"[email protected]",
"address": 
"310 General Courtney Hodges Blvd, Perry, GA 31069, USA",
"id": 
4612
},
{
"Store ID2": 
"1014",
"Business Name": 
"American-Structures II LLC",
"Phone": 
"800-716-5988",
"Email": 
"[email protected]",
"address": 
"2002 U.S. 78, Monroe, GA 30655, USA",
"id": 
4611
},
{
"Store ID2": 
"203",
"Business Name": 
"American-Structures",
"Phone": 
"800-716-5988",
"Email": 
"[email protected]",
"address": 
"3121 State Hwy 11, Mansfield, GA 30055",
"id": 
4610
},
{
"Store ID2": 
"157",
"Business Name": 
"Albany Auto Center",
"Phone": 
"229-432-7020",
"Email": 
"[email protected]",
"address": 
"3115 Sylvester Rd, Albany, GA 31705, USA",
"id": 
4609
},
{
"Store ID2": 
"1188",
"Business Name": 
"5 Star Custom Portable Buildings",
"Phone": 
"205-799-7090",
"Email": 
"[email protected]",
"address": 
"6602 McFarland Blvd, Northport, Alabama 35476, USA",
"id": 
4608
}
]

Here is my updated workflow:

Please share your workflow

Share the output returned by the last node

Here is a screenshot of the Edit Field WP node:

and the Edit Field Gsheet node:

Information on your n8n setup

  • n8n version: 1.59.3
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloudron
  • Operating system:

Hey @omrto , your description of the problem is not clear to me. Could you tell which node fails? It sounds like Merge node produces output, and it is “Edit Fields Back to WP” node that fails?

If so, could you share the JSON output of the Merge node that leads to failure to be able to test the workflow? Otherwise clarify where the failure takes place, please.

My apologies @ihortom . I updated my original post to be more clear.

Hey @omrto , thanks for clarification and nice to see you progressed further.

A few comments with regards to the latest issues. The error “The resource you are requesting could not be found.” rather suggests to me that either

  • The ID value is not right as you suggested (hence cannot be found to get PATCHed)
    OR
  • You (the authenticated user) have no access to that specific service (dealers)

Could you try to pool (GET) the “dealers” (rather than PATCH) and see if you can locate the entities in question? Do check the correct API for that kind of query.

@ihortom I have managed to get the whole workflow to complete but the data returned in the output of the last HTTP Request node is not updated, all except the modified date/time. What could possibly make it seem to update but not actually update? Weird. There isn’t even an error message.

I tried an authorized PUT in Postman and it returned the data with a 200 response but the data did not change.

EDIT: Yunohost is an app similar to Cloudron (what I’m using) and here’s a post where someone said basic authorization in n8n is not compatible with WP app passwords.

Here is the console output of my browser for one of the PUTs:

[Node: “HTTP Request to WP”]

  1. {headers: {…}, method: ‘PUT’, uri: ‘https://wp.omrto.com/wp-json/wp/v2/dealers/4610’, gzip: true, rejectUnauthorized: true, …}

  2. auth: {user: ‘********’, pass: ‘hidden’}

  3. encoding: null

  4. followAllRedirects: true

  5. followRedirect: true

  6. gzip: true

  7. headers: {accept: ‘application/json,text/html,application/xhtml+xml,a…cation/xml,text/;q=0.9, image/;q=0.8, /;q=0.7’}

  8. json: false

  9. method: “PUT”

  10. rejectUnauthorized: true

  11. resolveWithFullResponse: true

  12. timeout: 300000

  13. uri: “https://wp.omrto.com/wp-json/wp/v2/dealers/4610

  14. useStream: true

  15. [[Prototype]]: Object

I’m afraid I cannot help you with the 3rd party service. The issue you report does not appear to be n8n related. If there is a public documentation on API usage of the service in question I could go through that and see if anything is missing in your HTTP request. Apart from that, my hands are tied.

Well, after 4 days of troubleshooting I found out that the Toolset plugin does not support writing to custom fields without a bunch of custom code being added to WordPress (registering fields, etc, etc). I’m not a programmer so I tried ChatGPT and through a little trial and error I wound up with about 40 lines of code that fixed the issue.

I did run into a problem in n8n with the data not updating but that was fixed by adding JSON with placeholders to the Body of the HTTP Request. All is good now.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.