Pipedrive update organization Bad Request 400

Hey!

I’m trying to get our sales from our database into Pipedrive in a custom field.

I’m doing an api request to get the different amounts and split them in batches (25 per call) so I don’t hit the rate limit. After that I’m using the search organization Pipedrive Node with oAuth2 and look for a specific number. After that I’m trying to update the organizations, also through the Pipedrive Node with oAuth2, which got found the step before. Some organizations get updated but it never works completely, so I’m always getting a 400 Bad Request Error for an organization ID which is in our Pipedrive system and should be updatable.

Do I miss something in my workflow?
Thanks in advance!

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -400,
        600
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "=https://api.own-api.de/dks/umsaetze/{{$node[\"Date & Time\"].json[\"time\"]}}/{{$node[\"Date & Time1\"].json[\"time\"]}}",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        370,
        490
      ],
      "credentials": {
        "httpBasicAuth": "api.own-api"
      }
    },
    {
      "parameters": {
        "batchSize": 25,
        "options": {
          "reset": false
        }
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        800,
        490
      ]
    },
    {
      "parameters": {
        "functionCode": "    //var allItems = $items(“HTTP Request”, 0, $runIndex);\n    \n    //return items;\n    var newArray = [];\n    items[0].json.forEach(item => { //Loop des bestehenden Arrays\n       for (var k=0; k < newArray.length; k++) { //Prüfen ob id bereits im neuen Array vorhanden ist\n       if(item.b2ggkt.replace(/\\s/g, '') == newArray[k].json.id && item.k4ktn2.replace(/\\s/g, '') !== \"44011\") return;\n       }\n       var newItem = {json: {id: item.b2ggkt.replace(/\\s/g, ''), value: 0}}; //neues Item für neues Array bauen\n       items[0].json.forEach(innerItem => { //Nochmal das bestehende Array loopen, um alle innterItems mit der gleichen ID zu erhalten wie item.id\n          if(innerItem.b2ggkt == item.b2ggkt && innerItem.k4ktn2.replace(/\\s/g, '') !== \"44011\"){\n              newItem.json.value = newItem.json.value + parseInt(innerItem.betrag); //Werte addieren\n          }\n       });\n       if(newItem.json.value !== 0){\n      newArray.push(newItem);}\n    });\n    console.log(newArray);\n\nreturn newArray;"
      },
      "name": "Werte addieren1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        570,
        490
      ]
    },
    {
      "parameters": {
        "value": "={{$node[\"vor 12 Monaten\"].json[\"date_today\"]}}",
        "dataPropertyName": "time",
        "custom": true,
        "toFormat": "YYYYMMDD",
        "options": {}
      },
      "name": "Date & Time",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        200,
        490
      ]
    },
    {
      "parameters": {
        "functionCode": "var d = new Date(); // Today!\nd.setDate(d.getDate() - 365); // 1 year ago!\n\nitems[0].json.date_today = d.toISOString();\nreturn items"
      },
      "name": "vor 12 Monaten",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        20,
        490
      ]
    },
    {
      "parameters": {
        "functionCode": "var d = new Date(); // Today!\nd.setDate(d.getDate()); // 1 year ago!\n\nitems[0].json.date_today = d.toISOString();\nreturn items"
      },
      "name": "Heute",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -280,
        490
      ]
    },
    {
      "parameters": {
        "value": "={{$node[\"Heute\"].json[\"date_today\"]}}",
        "dataPropertyName": "time",
        "custom": true,
        "toFormat": "YYYYMMDD",
        "options": {}
      },
      "name": "Date & Time1",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        -120,
        490
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "organization",
        "operation": "search",
        "term": "={{$node[\"SplitInBatches\"].json[\"id\"]}}",
        "additionalFields": {
          "exactMatch": true,
          "fields": [
            "custom_fields"
          ]
        }
      },
      "name": "Pipedrive1",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        1020,
        490
      ],
      "credentials": {
        "pipedriveOAuth2Api": "p.ferdinand"
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "organization",
        "operation": "update",
        "organizationId": "={{$node[\"Pipedrive1\"].json[\"id\"]}}",
        "updateFields": {
          "customProperties": {
            "property": [
              {
                "name": "5656bb116f21fc45ee84a0a3155aeb8172dddf75",
                "value": "={{$node[\"SplitInBatches\"].json[\"value\"]}}"
              }
            ]
          }
        }
      },
      "name": "Pipedrive3",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        910,
        830
      ],
      "credentials": {
        "pipedriveOAuth2Api": "p.ferdinand"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Heute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Werte addieren1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "Pipedrive1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Werte addieren1": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "vor 12 Monaten": {
      "main": [
        [
          {
            "node": "Date & Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Heute": {
      "main": [
        [
          {
            "node": "Date & Time1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time1": {
      "main": [
        [
          {
            "node": "vor 12 Monaten",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive1": {
      "main": [
        [
          {
            "node": "Pipedrive3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive3": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @cvrooij!

I checked your workflow and you’re using the Search operation in the Pipedrive node. Is there a particular reason that you’re using that operation?

I created a test workflow to update the label field and it is working as expected. Do you get this error only for Custom Properties?

Hey @harshil1712!

The api-request to our own database gives back a value which have to match with a custom field in the Pipedrive organization, because of that I’m using the search operation to get the Pipedrive orga-ID.

I can’t test it with the basic Pipedrive fields because we have information in all of them.
But I don’t think it’s the custom property causing the problem. The error response by the update organization node is:

{"name":"StatusCodeError","statusCode":400,"message":"400 - {\"success\":false,\"error\":\"Bad request\",\"error_info\":\"Weitere Informationen über Pipedrive API finden Sie unter developers.pipedrive.com.\",\"data\":null,\"additional_data\":null}","error":{"success":false,"error":"Bad request","error_info":"Weitere Informationen über Pipedrive API finden Sie unter developers.pipedrive.com.","data":null,"additional_data":null},"options":{"timeout":300000,"headers":{"Accept":"application/json","Authorization":"Bearer 4910783:8022354:3c5a6412fb97891d0ab0fd327dfc62b85843afd7"},"method":"PUT","qs":{},"uri":"https://api.pipedrive.com/v1/organizations/15048","json":true,"body":{},"simple":true,"resolveWithFullResponse":false,"transform2xxOnly":false},"response":{"statusCode":400,"body":{"success":false,"error":"Bad request","error_info":"Weitere Informationen über Pipedrive API finden Sie unter developers.pipedrive.com.","data":null,"additional_data":null},"headers":{"date":"Wed, 25 Aug 2021 11:50:39 GMT","content-type":"application/json","transfer-encoding":"chunked","connection":"close","cf-ray":"68449aa31de94162-HAM","access-control-allow-origin":"*","cache-control":"no-cache","set-cookie":["pipedrive-cdl=eu-central-1;path=/;expires=Thu, 26 Aug 2021 11:50:39 GMT;secure","__cf_bm=79a23b06a8f9030f017770a98d8c6b637a057dd8-1629892239-1800-AdYyIAwnV3tSGC6GO0HaM5MU8ssV3ERUxMEXlUVOP/PDQLn9aMGAAcKd22KySk9P0bzgvYJjyLwl1+D4qa07XuM=; path=/; expires=Wed, 25-Aug-21 12:20:39 GMT; domain=.pipedrive.com; HttpOnly; Secure"],"strict-transport-security":"max-age=31536000; includeSubDomains","vary":"Accept-Encoding","cf-cache-status":"DYNAMIC","access-control-expose-headers":"X-RateLimit-Remaining, X-RateLimit-Limit, X-RateLimit-Reset","badi":"Routing: eu-central-1=>eu-central-1; Version: bd42; Host: bari;","expect-ct":"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"","x-content-type-options":"nosniff","x-correlation-id":"184c29de-1bcc-48ba-a321-4f71b0e3314e","x-frame-options":"SAMEORIGIN","x-ratelimit-limit":"160","x-ratelimit-remaining":"153","x-ratelimit-reset":"2","x-xss-protection":"1; mode=block","server":"cloudflare","alt-svc":"h3-27=\":443\"; ma=86400, h3-28=\":443\"; ma=86400, h3-29=\":443\"; ma=86400, h3=\":443\"; ma=86400"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.pipedrive.com","port":443,"hostname":"api.pipedrive.com","hash":null,"search":null,"query":null,"pathname":"/v1/organizations/15048","path":"/v1/organizations/15048","href":"https://api.pipedrive.com/v1/organizations/15048"},"method":"PUT","headers":{"Accept":"application/json","Authorization":"Bearer 4910783:8022354:3c5a6412fb97891d0ab0fd327dfc62b85843afd7","content-type":"application/json","content-length":2}}}}

I got the same error when I tried to update a custom property which wasn’t available in Pipedrive. After I added the custom field and added it’s field name (the unique filed name that Pipedrive generates), I was able to update it. I believe the issue is with the custom property that you’re trying to update.

But like 17 from these 25 request get executed… after some requests it just throws out this error. So the node is able to change the values of the custom field sometimes…

Are all these 25 organisations already present in Pipedrive? How many items does your first Pipedrive node with the search operation return?

Yes, all the organizations are already in Pipedrive.

Ohhhhh I think that is the problem, the first node returns 32 organizations because some organizations contain the same custom value that I search for. So the second pipedrive node has no values to use for the update of the custom field…

Yes, that seems to be the problem. You can either add an IF node to check for the condition or toggle the Continue on Fail option from the nodes setting tab.