Api- put method

Hi, er receive a “bad request” result from API and we don’t understand why.
we used PUT method with URL = https://different.pipedrive.com/api/v1/deals/266691?api_token=API_TOKEN

and data is
36bf501ebe475968893ea586106f2f8a5d4dd22f=%D7%91%D7%93%D7%99%D7%A7%D7%94

and this is the result
{“success”:false,“error”:“Bad request”,“error_info”:“Please check developers.pipedrive.com for more information about Pipedrive API.”,“data”:null,“additional_data”:null}

what is wrong with our request?

Hi Viki,

You’re trying to update a Deal is that correct?

Could you tell me what part of the Deal you’re trying to update? I can’t really tell from your info.

yes, we are trying to update a deal, a custom field named “מקור הגעה” (in Hebrew)

To update a Field on a deal you’ll want to use PUT/dealFields/{id}

You can also see a tutorial here to help you out.

Hi,
we are trying to update the deal field value and not the deal field itself.
we did it as written in step 3 but we received an error.
URL = https://different.pipedrive.com/api/v1/deals/266691?api_token=API_TOKEN

Hey Viki,

What are you inserting into the Body of the request and what Type of Field are you trying to update?

this is the body:
36bf501ebe475968893ea586106f2f8a5d4dd22f=%D7%91%D7%93%D7%99%D7%A7%D7%94

how can we know the field type?
the values are text and it has a dropdown list with options
image

That is either a Multiple Option or Single Option Field (it’s dependent on whether or not it allows multiple options so I can tell that the Body here is incorrect. For these types of Fields, there’s already defined Values/Options for this Field which are Integers.

You can use Pipedrive API v1 Reference to find out the Value IDs available for this Field and then use them when updating the Fields.

Hey Viki and David,

I’ve got exactly the same problem. I’m also trying to update a MultipleOption Field on a deal. However, even when using the option id in the body of the PUT request I can’t get it to work.

I don’t know if that’s also the case for Viki, but in my case, that PUT Request is triggered by a deal.added webhook message sent from pipedrive to another piece of software.

Endpoint: /deals/{id}
What I’ve tried so far:

  • Sending a stringified int id in the body:
    {“9ad111c18fec4addc2130a29a3bb597088931897”: “235”}
  • Sending it as a JSON int:
    {“9ad111c18fec4addc2130a29a3bb597088931897”: 235}

Both resulted in a “Bad Request” response.

Could that be a timing issue, e.g. sending the PUT request to soon after receiving the webhook message?

Hi Stefan,

Are you adding the API Token of the Field or the Field ID? From the example it looks like it’s API Token.

this is a single option field but it has defined values and we tried to set one of these values.
can you please send an example of how we should find out the value ids? i cant find it, and can we get the value itself with the value id?

If you use the GET /dealFields (or whichever Fields you’re looking for) endpoint, you’ll see the IDs of all your (Deal) Fields, for Single and Multiple Option Fields you’ll see the Values and IDs for all of the options you have for those Fields as well:

For example:

Hi David,
Thank you very much for your reply.

It’s the API Token (“9ad111c18fec4addc2130a29a3bb597088931897”) and the id of the option I want to set this to (“235”).

Here’s the definition of the field (from the /dealFields endpoint):

{
        "id": 12499,
        "key": "9ad111c18fec4addc2130a29a3bb597088931897",
        "name": "Zeiterfassung in Timetac",
        "order_nr": 58,
        "field_type": "enum",
        "add_time": "2019-09-25 09:28:51",
        "update_time": "2020-10-19 13:12:20",
        "last_updated_by_user_id": 3784184,
        "active_flag": true,
        "edit_flag": true,
        "index_visible_flag": true,
        "details_visible_flag": true,
        "add_visible_flag": true,
        "important_flag": true,
        "bulk_edit_allowed": true,
        "searchable_flag": false,
        "filtering_allowed": true,
        "sortable_flag": true,
        "options": [
            {
                "label": "Ja",
                "id": 235
            }
        ],
        "mandatory_flag": false
    }

In this case, the Body of your PUT request needs to include

"9ad111c18fec4addc2130a29a3bb597088931897": "235"

So it needs to be what I already tried. I’ll try to increase the time between receiving the webhook deal.added message and the PUT request then. Thankfully I’ve already implemented the last part in an async function and increasing the wait time is trivial. I’ll report back if that changes anything. Thank you David.

1 Like

Well, unfortunately increasing the delay to 60 seconds between receiving the deal.added webhook message and sending the PUT Request didn’t help.
I’ll try to capture the outgoing PUT Request in full and post it here for further troubleshooting.

I was able to capture an outgoing request:

PUT /v1/deals/6146?api_token=xxxxxxxx HTTP/1.1
Host: api.pipedrive.com
Accept: application/json
Content-Type: application/json

"eyI5YWQxMTFjMThmZWM0YWRkYzIxMzBhMjlhM2JiNTk3MDg4OTMxODk3IjoiMjM1In0="

I’ve crossed out the api_token, but confirmed that it’s correct. The base64 encoded body decodes to:

{"9ad111c18fec4addc2130a29a3bb597088931897":"235"}

@David ist there anything missing from the request or any obvious errors that you can see?

edit: I believe I’ve found the problem. Our API client implementation would automatically marshall a map to json, but I had an extra step to marshall the body to json beforehand. So I had doubled the json marshalling for the request body, which would explain the base64 encoded body above.
I’ll report back if it works.

1 Like