Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a contact to a marketing list #53

Open
billstennett opened this issue Feb 9, 2018 · 6 comments
Open

Adding a contact to a marketing list #53

billstennett opened this issue Feb 9, 2018 · 6 comments

Comments

@billstennett
Copy link
Contributor

billstennett commented Feb 9, 2018

I am trying to add a contact to a marketing list using the contact GUID.

I am able to get a list object from CRM using he following code:

$list = $service->entity( 'list', $listguid ); where $listguid is the guid of the marketing list I want to work with

but I'm not sure if this is the right approach. I suspect this only allows me to manipulate the list itself as opposed to adding contacts to it.

Can i use the AddListMembersListRequest function which looks to take a listguid and conatct guids as parameters? The problem is that I have no idea how to call a function like this using the php toolkit

I'd appreciate any advice on how to approach this problem.

I'm wondering if the executeAction method might be the way to go? Somethng like:

$result = $service->executeAction('AddListMembersList' $listguid ,$memberid); (which doesn't work as I've written it but somehow seems close).

Cheers,

Bill

@georged
Copy link
Contributor

georged commented Feb 12, 2018

Hi @billstennett

executeAction is for executing custom actions, it is not the Execute method that you are after. What you need to do is to build your own SOAP packet for AddListMembersListRequest. SoapRequestGenerator.php file already contains few requests, just follow the same flow.

The reason why we didn't build it is simply the volume. CRM has over 200 different requests, it wouldn't be feasible for us to try and cover all of them. We do encourage that people form the project and add new request types as needed.

You'd need to figure out the parameters, of course. Download CRM SDK (the latest downloadable version) and check out SoapLogger sample. It generates jscript but packets are all the same.

HTH
George

@billstennett
Copy link
Contributor Author

Thanks very much for the reply George.

I think I have the SOAP packet I need but I can't see how to send it. Should I use the "attemptSoapResponse()" function in Client.php? I did try playing around with it but not getting anywhere so far.

Also, I am struggling to see the actual XML response that is being sent to the server. I can see reference to a "$logger" in various parts of the library code but I can see no edocumentation on how to use it. Ist here a variable somewhere to set to get it to display messages or something similar?

I'd appreciate it if you are able to point me in the right direction with this.

Cheers,

Bill

@georged
Copy link
Contributor

georged commented Feb 12, 2018

Hi Bill,

actually, take a look at executeAction in Client.php module. This is something that you'd model your request after.

  • instead of generateExecuteActionRequest you'd want your custom generateAddListMemberListRequest where you do the SOAP formatting specific to that request
  • after you execute loadXml to get your response, you'd need to parse that response which will be serialized AddListMemberListResponse (usually there is nothing to parse if it's successful but there maybe some IDs returned - check the docs for that response)

$logger is a generic logging interface that gets attached when client is constructed. Whatever is your favorite logger, really depends on the environment.

HTH
George

@billstennett
Copy link
Contributor Author

billstennett commented Feb 22, 2018

Hi George,

so I have made progress on this and thought it might be interesting to share where I have got to so far. I am now able to add one or more contact to a marketing list. I found that I can use executeAction from client.php but adding a few lines of code to handle a field type of "ArrayOfguid". The additions are generic and it made me wonder if this is something that could be included in the library. The code I added was as follows:

case 'arrayofguid': $xmlType = 'ArrayOfguid'; $entity = $xmlValue; $xmlTypeNS = 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'; $entityValue = $executeActionRequestDOM->createElement('c:value'); foreach ( $entity as $contact_guid ) { $entityValue->appendChild($executeActionRequestDOM->createElement( 'd:guid', $contact_guid )); }; // end foreach $xmlValue = null; break;

I was then able to call exectueAction as follows:

$result = $service->executeAction( 'AddListMembersList', array( array('key'=>'ListId', 'value' => $listguid, 'type' => 'guid'), array('key'=>'MemberIds', 'value' => $memberids, 'type' => 'arrayofguid') ), 'AddListMembersListRequest' );

Cheers,

Bill

@georged
Copy link
Contributor

georged commented Feb 22, 2018

Hi Bill,

cool, that's great! Can you create a pull request for the AddListMembersList implementation and we'll see what can be done about making it generic.

Thanks
George

@billstennett
Copy link
Contributor Author

billstennett commented Feb 23, 2018

Hi George

I have created a pull request with the changes I made to soaprequestsgenerator.php to handle the xml type "ArrayOfguid"

Cheers

Bill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants