DavidRouyer / pipedrive-dotnet

Pipedrive.net is an async .NET Standard client for pipedrive.com
MIT License
38 stars 46 forks source link

Still Active? Need info on how to update Adress/phone data on organizatoin #74

Closed evagelos21 closed 3 years ago

evagelos21 commented 3 years ago

Im trying like this but no luck: What am i missing?

        IDictionary<string, ICustomField> CustomFields = new Dictionary<string, ICustomField>();
        CustomFields.Add("DETAIL", new MyCustomField() { Address = "My Address", Tel = "1234657890" });

        var result = await client.Organization.Create(new NewOrganization("vagelis")
        {
            Name = "Vagelis",
            OwnerId = UserId,
            VisibleTo = Visibility.shared,
            CustomFields = CustomFields
        });
kardoaw commented 3 years ago

Is "DETAIL" your custom field name? I suspect it is and you should use custom field key instead of name. You can query all organization fields and find field key by name.

evagelos21 commented 3 years ago

No, my custom field name is "Country Name" I cannot understand how to c# coding !!! i have managed to add NEW Organization, but i cannot understand how to update

DavidRouyer commented 3 years ago

Take a look at the Pipedrive REST API: https://developers.pipedrive.com/docs/api/v1/ If you create a custom field on Pipedrive, Pipedrive will generate a unique API key for your field which look like 034b2499f80a0b36c289efb7811f842bf22fd998 and can be found on the Data fields section in the settings UI. You can also fetch them by using the https://developers.pipedrive.com/docs/api/v1/#!/OrganizationFields endpoint.

DavidRouyer commented 3 years ago
var organization = await client.Organization.Get(1);

// Address is a default organization field created by Pipedrive so you have access to it
Console.WriteLine($"Address: {organization.Address}");
Console.WriteLine($"FormattedAddress: {organization.AddressFormattedAddress}");
Console.WriteLine($"StreetNumber: {organization.AddressStreetNumber}");
Console.WriteLine($"Route: {organization.AddressRoute}");
Console.WriteLine($"Country: {organization.AddressCountry}");
// ...

var updatedOrganisation = organization.ToUpdate();
updatedOrganisation.CustomFields["address"] = new AddressCustomField("2, avenue des Champs Elysées, Paris, France", "", "2", "rue des Champs Elysées", "", "", "", "", "", "", "2, avenue des Champs Elysées, Paris, France");

// Get your organization field API key
// updatedOrganisation.CustomFields["your-field-api-key"] = new StringCustomField("0606060606");

await client.Organization.Edit(organization.Id, updatedOrganisation);
evagelos21 commented 3 years ago

Thanks, now it seams easy to me

dombarnes commented 2 years ago

This seems a bit confusing tbh. Address is not a custom field yet we behave like it is one. According to some posts to the Pipedrive community, when you send an "address" field, it will auto-parse the string you give and work out the split address fields (via Google API's). So if I send "1 High Street, New Town, New State" it works out 1 High Street is line 1. So it would be useful to have a constructor for AddressCustomField that takes a single string to send to address. If I'm doing this in Postman, I just send

{
    "address": "1 High Street, New Town, New State"
}

Annoyingly the official docs lack any kind of proper documentation for this https://developers.pipedrive.com/docs/api/v1/Organizations#updateOrganization Doesn't indicate thats how you update any field (and neither does their Postman config file). https://devcommunity.pipedrive.com/t/address-in-organization-api/1391/10

dombarnes commented 2 years ago

Follow up observation. It looks like the pipedrive API ignores setting other address fields. For example sending an address and an address_street_number, the address_street_number is ignored (or overridden) if I set it to something that doesn't match the address. Similarly, you can't just send address_street_number as it returns a 400 bad request. So sending anything beyond address is redundant it seems.