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...

Comments

matthewgsommers created an issue. See original summary.

john_a’s picture

HI 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.

john_a’s picture

Hi 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.

john_a’s picture

Status: Active » Closed (works as designed)

Tentatively closing this issue, since the v2 token request can be set up in the config.

dave reid’s picture

Status: Closed (works as designed) » Active

Trying to use the new /v2/token URL for the token request results in the following error:

{
    "error": "unsupported_grant_type",
    "error_description": "Use \"authorization_code\" or \"refresh_token\" or \"client_credentials\" or \"urn:ietf:params:oauth:grant-type:jwt-bearer\" as the grant_type.",
    "error_uri": "https://developer.salesforce.com/docs"
}
john_a’s picture

StatusFileSize
new1.15 KB

Hi 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.

dave reid’s picture

I 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.

john_a’s picture

StatusFileSize
new1.2 KB

Yes, 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.

john_a’s picture

StatusFileSize
new6.99 KB

New patch created. This includes:

  • Changes to the settings form:
    • request_token_url - this is now the scheme and domain for the auth call only.
    • request_token_version (dropdown with options v1 or v2.
  • Schema updated.
  • Install config updated.
  • MarketingCloudSession->requestToken() now generates the url dynamically, based on request_token_url and request_token_version.
  • marketing_cloud_update_8002:
    • Fetch existing request_token_url, validate if it is v1 or v2 - store this in request_token_version.
    • Existing request_token_url replaced with schema and domain only.

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!

john_a’s picture

We 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

john_a’s picture

Status: Active » Needs review
john_a’s picture

Can 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.

alex voloshchenko’s picture

john_a you have wrong property name for v2 in requestToken function.
You should return $data->access_token instead $data->accessToken for v2.

john_a’s picture

StatusFileSize
new6.76 KB
new6.76 KB

Many 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.

john_a’s picture

john_a’s picture

Assigned: Unassigned » john_a
Status: Needs review » Needs work
john_a’s picture

Version: 8.x-1.x-dev » 8.x-1.0
john_a’s picture

Category: Support request » Bug report
john_a’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Category: Bug report » Support request
john_a’s picture

Status: Needs work » Needs review

The 3060349-19.patch is against 8.x-1.0, and is committed to 8.x-1.0-dev (my bad)

vani.s’s picture

Version: 8.x-1.x-dev » 8.x-1.0
StatusFileSize
new55.49 KB

Hi,

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

vani.s’s picture

vani.s’s picture

StatusFileSize
new79.76 KB
john_a’s picture

Hi 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.

vani.s’s picture

StatusFileSize
new52.08 KB

Hi 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!!

john_a’s picture

Hi 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 __construct and create functions 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:

$this->marketing_cloud_contacts_service->updateContacts($data);
vani.s’s picture

Status: Needs review » Reviewed & tested by the community

Hi 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!!

  • john_a committed 3642a17 on 8.x-1.x
    Issue #3060349 by john_a: /v2/token for Server to Server Integration...
  • john_a committed 488863e on 8.x-1.x
    Issue #3060349 by john_a, matthewgsommers, Dave Reid, Alex Voloshchenko...
john_a’s picture

Status: Reviewed & tested by the community » Fixed
john_a’s picture

Status: Fixed » Closed (fixed)
garikipati’s picture

Thanks John and Vani! I have integrated only marketing_cloud_contacts and had same issue but after the patch everything works fine!