Bad Request to add installment payment using API

Hello,

For some reason I’m receiving a “Bad Request” error 400 when trying to create a new payment installment using the API.

I suspect the “payments” array Object I’m passing in the API is wrongly formatted, but couldn’t find any good example to pass arrays using POST on Pipedrive.

I’m using Python, my code:

    url = "https://api.pipedrive.com/v1/subscriptions/installment?api_token=MYTOKEN"

    payload = {
        "deal_id": 123,
        "currency": "USD",
        "payments": [{"amount":"123", "description":"test", "due_at":"2022-05-26"}]
        }
            
    r = requests.post(url, data=payload)

Also got a Bad Request testing on Postman:

Any ideas?

I found a solution, the json body must be encoded with json.dumps:

  url = "https://api.pipedrive.com/v1/subscriptions/installment?api_token=MYTOKEN"

  payload = json.dumps({
      "deal_id": deal_id,
      "currency": "USD",
      "payments": [
          {"amount": "123", "description":"test", "due_at":"2022-05-26"}
      ],
      "update_deal_value": False
  })
          
  r = requests.post(url, data=payload, headers={'accept': 'application/json','content-type':'application/json'})