Hello,
This module is great, so thank you for that first of all!
This is a feature / support request more so than anything. My upfront question is: Is there any intent to update the module to be compatible with a server-to-server integration via /v2/token for auth?
For a little bit more context, I'm currently working on a Drupal to Marketing Cloud integration utilizing the Interaction API to target a data extension within one of our Marketing cloud instances. That functionality is already working as required, however it is using the legacy API call for the auth token (/v1/requestToken). This isn't necessarily a bad thing since it still works. The issue that I'm running into is that we recently created a new instance of Marketing Cloud and that instance uses the new auth mechanism (/v2/token), which is not compatible with this module as it stands. So by that measure, we now have to separate mechanisms to submit data.
So I've been modifying the module locally to try and make the new auth process work but it hasnt exactly been easy going. Do you think it would be a better idea to modify the marketing_cloud module so that it can handle both requests or would creating a custom / glue module that specifically handles the new API format?
Would be more than willing to share any successful work that comes out on my end!
Any thoughts or guidance would be appreciated. Everything helps!
Thank you!
Link for reference: https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.met...
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | mc-config.JPG | 52.08 KB | vani.s |
| #23 | Marketing Cloud Example.png | 79.76 KB | vani.s |
| #14 | 3060349-14.patch | 6.76 KB | john_a |
| #9 | 3060349-9.patch | 6.99 KB | john_a |
| #8 | 3060349-8.patch | 1.2 KB | john_a |
Comments
Comment #2
john_a commentedHI Mathew,
Many thanks for the report and feature request. Considering you've faced this after creating a new account with MC, it's fair to assume that others will face this too, so it's something this module should cover. I've gone through the docs online, and it seems that although the token request now seems to be locked into v2, all the resource calls are still on v1. I could not find any information on the roadmap for MC with versioning. Do you know if the whole suite of resources are going to be updated, or if the v2 token is compatible with the v1 rest resources?
In the meantime, I'm going through the docs to find more information.
Comment #3
john_a commentedHi Mathew,
I've not had time to look into this. As an alternative, there is a field on the config page that allows you to enter a different URL: 'Salesforce auth token request URL'. I think this should cover most other people's requirement, although I'm not sure of this will suit you , considering you have multiple endpoints.
Comment #4
john_a commentedTentatively closing this issue, since the v2 token request can be set up in the config.
Comment #5
dave reidTrying to use the new /v2/token URL for the token request results in the following error:
Comment #6
john_a commentedHi Dave,
It looks like the params are slightly different in v2 vs v1: https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.met....
I have a quick fix patch, please could you test this? I think ideally, if this fixes the issue, the config form should be altered to handle the different versions - doing a strpos test is not ideal.
Comment #7
dave reidI believe this is missing the grant_type parameter as well for the v2/token request. By default, server-to-server applications should use grant_type: client_credentials.
Comment #8
john_a commentedYes, you're quite right, I missed that. I've created a new patch for the workaround until I get the time to set up a new MC account, refactor the config form, and test that with a new account.
This patch will require you to set the request_token_url to scheme and subdomain only, e.g. "https://YOUR_SUBDOMAIN.auth.exacttargetapis.com" for v2 or "https://auth.exacttargetapis.com" for v1.
Comment #9
john_a commentedNew patch created. This includes:
I have a remaining issue with the update hook: it is always computing version as v1, even if the original request_token_url contains 'v2'. It looks as if the value for request_token_url is being updated from marketing_cloud.settings.yml before it hits the marketing_cloud_update_8002() function.
If anyone knows what's going on here, advice would be appreciated!
Comment #10
john_a commentedWe need to get the issue raised in #9 fixed, but I'd like to get a preliminary review done, if possible, so that we can make sure the authentication works with v2
Comment #11
john_a commentedComment #12
john_a commentedCan anyone confirm this patch works with v2? If it passes, I might let this go to release, because v2 token auth was not working before anyway.
Comment #13
alex voloshchenko commentedjohn_a you have wrong property name for v2 in requestToken function.
You should return $data->access_token instead $data->accessToken for v2.
Comment #14
john_a commentedMany thanks for the review Alex
Apologies to all, I have spoke to my current and previous employers, and none of them have access to new MC accounts with v2 auth, so I cannot validate this myself.
New patch attached.
Comment #15
john_a commentedComment #16
john_a commentedComment #17
john_a commentedComment #18
john_a commentedComment #19
john_a commentedComment #20
john_a commentedThe 3060349-19.patch is against 8.x-1.0, and is committed to 8.x-1.0-dev (my bad)
Comment #21
vani.s commentedHi,
I'm using drupal 8.8.0 Installed mc module and using new auth mechanism (/v2/token) and applied #14 patch..after submitting the webform getting error attached in screenshot ..Does anyone have solution on this?
Thank You
Comment #22
vani.s commentedComment #23
vani.s commentedComment #24
john_a commentedHi Vani,
What is your config values for "Salesforce auth token request URL" and "Salesforce auth token request version"?
Did you edit the endpoint definitions in the config page? According to https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/p..., the URI for the rest (except for token auth) for the latest version should still be v1.
Comment #25
vani.s commentedHi John,
Salesforce auth token request URL is "https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com" and i'm using V2 version.
I'm tried to generate access token and it's working fine...i m not edited any endpoint definitions...i'm trying to integrate only marketing_cloud_contacts endpoint definitions. Please suggest how can we integrate only contacts Endpoints with using of marketing_cloud_example module.
Thanks!!
Comment #26
john_a commentedHi Vani,
If the patch is working and you are able successfully send a request using the v2 auth, it would be great if you could mark the ticket as "reviewed and tested". Then I could apply the patch to trunk and release a new version, unless the patch still needs work...
The example module is just to demonstrate how to use the services. See https://www.drupal.org/docs/8/modules/marketing-cloud for more documentation on how to use this module. How to integrate it into your custom module depends on your use case. But essentially, you need to take a look at
ContactsService.php, which contains the definitions of all the services defined in that sub-module and you can see the inputs contract, reference to the MC documentation, etc. You can then do something like:$response = \Drupal::service('marketing_cloud_contacts.service')->updateContacts($data);Or more correctly, to use dependency injection (using
__constructandcreatefunctions in your class and/or defining it in your services.yml file. https://code.tutsplus.com/tutorials/drupal-8-properly-injecting-dependen... has some good examples) and call it as a private member:Comment #27
vani.s commentedHi John,
Thanks for the update..i will integrate marketing_cloud_contacts endpoint definitions as my use case.i will take into your suggestion and implement it.
Thank You!!
Comment #29
john_a commentedComment #30
john_a commentedComment #31
garikipati commentedThanks John and Vani! I have integrated only marketing_cloud_contacts and had same issue but after the patch everything works fine!