mautic / developer-documentation

Mautic Developer Documentation
https://developer.mautic.org
Other
28 stars 93 forks source link

API - List Contacts Companies - Search Parameter #158

Open YannickBiet opened 7 years ago

YannickBiet commented 7 years ago
Q A
Bug report? No
Feature request? Yes
Enhancement? No

Description:

Currently the REST API for companies listing is not filterable ! https://developer.mautic.org/#list-contact-companies

It asks ages to get a list from Mautic that owns hundred of thousands companies !

As it is already implemented in Contacts, it would be great to have the same possibilities with Companies to have the same level of functionalities whatever we want to deal / sync contacts or companies

If a bug:

Q A
Mautic version 2.9.2
PHP version 7.0.12
--- Want to back this issue? **[Post a bounty on it!](https://app.bountysource.com/issues/95578007-api-list-contacts-companies-search-parameter?utm_campaign=plugin&utm_content=tracker%2F14623305&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://app.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F14623305&utm_medium=issues&utm_source=github).
escopecz commented 7 years ago

Could you please provide some examples of what's wrong and/or what your suggestions are? I don't understand it from your request.

YannickBiet commented 7 years ago

Currently when we want to push from CRM a new contact to mautic (not existing into Mautic) and we want to send at the same time accounts' details. We need so to retrieve the account based on the account name (for example) to identify if the account is already existing in Mautic.

Currently we must load the full Accounts list to retrieve thousands of answers to try to match our account name as we can't refine our API call with a search string like Contacts list.

Does this make sense for you ?

escopecz commented 7 years ago

Why don't you use

GET /api/companies?search=mautic

replace mautic with the company name you are looking for

YannickBiet commented 7 years ago

https://developer.mautic.org/#get-company

This list is not filterable.

There 's no filters available in the documentation.

TBH we used the search filter as in the Contacts list filter (with extended criterias) but it didn't work. As documentation said that the list is not filterable, we assumed that we cannot do any search.. we were (partially) wrong.

Thanks for the tip ! We will use that. Still we can keep that FR to provide:

escopecz commented 7 years ago

Will you have time to update the docs? https://github.com/mautic/developer-documentation

YannickBiet commented 7 years ago

@captivea-qch Can you help on this one ?

npracht commented 6 years ago

@captivea-ylb could you please carry that as requested by @YannickBiet ? Thanks !

laabidi21 commented 4 years ago

@escopecz it is possible to search for contacts according to a company (we have the company ID). and we are looking for the contact list ?

escopecz commented 4 years ago

Should be possible to use the company search command. But it uses company name instead of ID. Is that a problem? company:"Company name"

laabidi21 commented 4 years ago

@escopecz the problem is that the name of the company is not unique. the company ID will be more precise. is it possible to filter contacts by company ID? or the only way is to use the company name?

escopecz commented 4 years ago

Contacts to companies relationship is stored in the companies_leads table. And you can filter this table via API as it's considered a stat table https://developer.mautic.org/#stats. But you'll work with IDs only there.

laabidi21 commented 4 years ago

@escopecz with this method of accessing the relations table and seeing the IDs of the contacts of such a Company, will be slower to access the content of the properties of the contacts. (if in a company, I have 1000 contacts, I will then make 1000 API requests to have all the contacts with get(ID)). a short question: if I have two companies with the same name XX, and I request them from API Call the contacts that contain this company (company:"XX"); I will habe the contacts of the two company or that of the first company in the list?

laabidi21 commented 4 years ago

@captivea-ylb @escopecz @npracht Can you help on this one ?

escopecz commented 4 years ago

I don't know these nuances from the top of my head. Please do some tests.

laabidi21 commented 4 years ago

@escopecz How to get Custom Data Type (List of Country, List of region ...) of Fields WITH the API Library ?

escopecz commented 4 years ago

I'm not aware of a API endpoint for those. But you can access them on GitHub directly. They are in JSON format. For example countries are here:

https://raw.githubusercontent.com/mautic/mautic/c9a0e09e62c03c91000e0b79578b744c11347f8f/app/bundles/CoreBundle/Assets/json/countries.json

laabidi21 commented 4 years ago

@escopecz I used your proposal to find the contacts of a Company with: company: "Company name" is it possible to find contacts who have no company in relation? (Without company in relationships)

laabidi21 commented 4 years ago

@escopecz Please I used your proposal to find the contacts of a Company with: company: "Company name" is it possible to find contacts who have no company in relation? (Without company in relationships)

laabidi21 commented 3 years ago

@escopecz it is possible to change the Label of the standard Field in Mautic from API ? I have Version 3.0.1 // Get contact field context: $fieldApi = $api->newApi("contactFields", $auth, $apiUrl); $id = 1; $data = array( 'label' => 'API test field', 'type' => 'text', );

// Create new a field of ID 1 is not found? $createIfNotFound = true;

$result = $fieldApi->edit($id, $data, $createIfNotFound);

I have a 500 type error. "message":"Looks like I encountered an error (error #500)

escopecz commented 3 years ago

Should be possible. Check the logs what the error is.

laabidi21 commented 3 years ago

@escopecz I didn't write the sql request. but I wrote the PHP code for API access. but it translates with the request: An exception occurred while executing 'UPDATE lead_fields SET is_published = ?, date_modified = ?, modified_by = ?, modified_by_user = ?, label = ?, is_required = ?, is_visible = ?, is_short_visible = ?, is_listable = ?, is_unique_identifer = ?, field_order = ? WHERE id = ?' with params [0, "2020-10-07 05:06:16", 3, "UserName", "Hauptadresse Stadt", null, null, null, null, null, 0, 13]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'is_required' cannot be null" at PDOStatement.php:121

escopecz commented 3 years ago

Alright. It's a bug then. The is_required property should be set to false if not provided. However there is a way around it if you provide the value in your API request. Try this:

$fieldApi = $api->newApi("contactFields", $auth, $apiUrl);
$id = 1;
$data = [
    'label' => 'API test field',
    'type' => 'text',
    'isRequired' => false,
];

// Create new a field of ID 1 is not found?
$createIfNotFound = true;

$result = $fieldApi->edit($id, $data, $createIfNotFound);
laabidi21 commented 3 years ago

@escopecz when i set 'isRequired' false, it jumped to an error -> 'is_visible' cannot be null. I will try to give value to all the attributes of the DB. can you be able to help me give me the right values (True or False)? $data = array( 'label' => $vname, 'type' => $type, 'isRequired' => false, 'is_visible' => true, 'is_short_visible' => false, 'is_listable' => false, 'is_unique_identifer' => false, );

laabidi21 commented 3 years ago

@escopecz
With $data = array( 'label' => $vname, 'type' => $type, 'isRequired' => false, 'is_visible' => false, 'is_short_visible' => false, 'is_listable' => false, 'is_unique_identifer' => false, ); Error Log 'UPDATE lead_fields SET is_published = ?, date_modified = ?, label = ?, is_visible = ?, is_short_visible = ?, is_listable = ?, is_unique_identifer = ?, field_order = ? WHERE id = ?' with params [0, "2020-10-07 08:20:49", "Vorname", null, null, null, null, 0, 2] -> SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'is_visible' cannot be null -> despite 'is_visible' had the value FALSE in the array

escopecz commented 3 years ago

Change the underscores with camel case as I did with the isRequired. E.g. is_visible => isVisible.

laabidi21 commented 3 years ago

@escopecz
I have upgrade to version 3.0.1. php var/www/html/mautic/bin/console mautic:segments:update earlier, worked fine. but now after the upgrade I got an error. PHP Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0 Could not open input file: var/www/html/mautic/bin/console

escopecz commented 3 years ago

@Ziedpad let's not mix completely different problem into this. Please create 1 GitHub issue for each problem you face. But in your case it's easier to find the answer when you google the error message. This is the first result: https://stackoverflow.com/questions/39204990/php-startup-unable-to-load-dynamic-library-usr-lib-php-20151012-php-mysqli-dll

pintobikez commented 3 years ago

Same problem here. It is very annoying to search companies. There are no filters available, and if the company name has accents, the search doesn't work at all.

Example, if I have a company named: John FarmacĂȘutica, and I try to search for it, mautic will never return a value. I've tried to parse it to utf8 and encode the uri component and nothing....