Post Organization -custom floating window app

I’m making a custom floating window app and the project is based on the react pipedrive phone call template.

I would need to make a post Organization. The post organization method works, but
I dont know how to fill the other custom data fields:

I can get the ID of the customized field but even If I change the “nip” to the apki key it still wont post the neccessary data.

Here is my code:

import { OrganizationsApi, OrganizationFieldsApi, NewOrganization } from 'pipedrive';
import logger from '../../shared/logger';
import { getAPIClient } from '../../shared/oauth';
const log = logger('Get Organization API 📚');

const handler = async (req, res) => {
    try {
      const d = req.body;
      const client = getAPIClient(req, res);
      log.info('Initializing client');
      const api = new OrganizationsApi(client);
     
      const newOrganization = await api.addOrganization(
        NewOrganization.constructFromObject({
          name: d.name,
          address: d.address,
          nip: d.nip,
        })
      );

      const organization = newOrganization.data;
      
      log.info('Returning response');
      res.status(200).json(organization);
    } catch (error) {
      log.info('Failed posting organization');
      log.error(error);
      res.status(500).json({ success: false, data: error });
    }
  };

Can someone give me a hint how to modify this request in order to post to a custom field?

And here is my method that calls to the handler:

function createOrganization(){

  let preparedJsonBody = JSON.stringify({"name": orgNameField,
  "address": adressField,
  "7b4ee6ab150271090998e28fcdf397f97b842435": nip})

  console.log(preparedJsonBody);

  fetch('/api/postOrganization', {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    method: 'POST',
    type: 'application/json',
    body: preparedJsonBody
  })
}

I had the wrong body. It should have looked like this:

  const newOrganization = await api.addOrganization(
    NewOrganization.constructFromObject({
      name: d.name,
      address: d.address,
      "7b4ee6ab150271090998e28fcdf397f97b842435": d["7b4ee6ab150271090998e28fcdf397f97b842435"],
    })
  );
1 Like

This topic was automatically closed after 60 days. New replies are no longer allowed.