0

I can authenticate the REST API through Postman, but I've tried both the python FuelSDK and C# SDK but I can't seem to get either of them to connect to my instance of Marketing Cloud. I think I'm just getting the endpoints wrong.

Installed Packages

This is what my installed packages look like: Installed Packages

Postman

Postman seems to work, when I send the following request to https://blah.auth.marketingcloudapis.com/v2/token

{ "grant_type": "client_credentials"
, "client_id": "..."
, "client_secret": "..."
, "scope": "data_extensions_read data_extensions_write"
, "account_id": "..." }

The response is:

{
    "access_token": "...",
    "token_type": "Bearer",
    "expires_in": 1079,
    "scope": "data_extensions_read data_extensions_write",
    "soap_instance_url": "https://blah.soap.marketingcloudapis.com/",
    "rest_instance_url": "https://blah.rest.marketingcloudapis.com/"
}

So I think postman works.

C# FuelSDK

However not in C#. I installed v1.1.1 of the FuelSDK through NuGet. When I try running the following code in C#:

var client = new ETClient(new NameValueCollection {
    { "clientId", "CLIENTID" },
    { "clientSecret", "SECRET" },
    { "authEndPoint", "https://blah.auth.marketingcloudapis.com/v2/token" },
    { "soapEndPoint", "https://blah.soap.marketingcloudapis.com/" },
    { "restEndPoint", "https://blah.rest.marketingcloudapis.com/" },
});

I get an exception on that line:

System.Net.WebException "The remote server returned an error: (400) Bad Request."

When I change the authEndPoint to https://blah.auth.marketingcloudapis.com/ I get:

"The remote server returned an error: (596) ."

When I remove authEndPoint all together I get:

"The remote server returned an error: (401) Unauthorized."

Python FuelSDK

My ~/.fuelsdk/config.python looks like this:

[Web Services]
appsignature: none
clientid: CLIENTID
clientsecret: CLIENTSECRET
defaultwsdl: https://blah.soap.marketingcloudapis.com/ETFramework.wsdl
baseapiurl: https://www.marketingcloudapis.com
authenticationurl: https://blah.auth.marketingcloudapis.com/v2/token
soapendpoint: https://blah.soap.marketingcloudapis.com/
wsdl_file_local_loc: /tmp/ExactTargetWSDL.s6.xml

When I run the following code:

client = FuelSDK.ET_Client()

I get the following error:

Exception: Unable to validate App Keys(ClientID/ClientSecret) provided:
{
'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'
}

When I change authenticationurl to https://blah.auth.marketingcloudapis.com/ I get the following exception:

...
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

When I remove authenticationurl, I get the following exception:

Exception: Unable to validate App Keys(ClientID/ClientSecret) provided: {'message': 'Unauthorized', 'errorcode': 1, 'documentation': ''}

I'm at wit's end, does anyone know what the problem is?

2

I was running into the same issue and i looked at client.py. Looks like it was setup only to handle v1/requestToken and not v2/token. So i tried to edit the client.py to make sure the grant_type and client_id and client_secret is passed over then hand to change the response variables it was parsing. Even after all that my response was Post response:False Code: HTTPStatus.OK Message: Error: API Permission Failed. Result Count: 0 Results: []

| improve this answer | |
  • Sadly I think you're right, I ended up downloading the source code, and it was too out of date I didn't know where to start... – mercifulhop Apr 25 '19 at 2:25
1

I had the same issue. FuelPHP seems to be outdated and full of bugs, so I'm sending my requests directly with CURL...

Here's a working example:

    $server = "https://blablabla.auth.marketingcloudapis.com/v2/token";
$json = json_encode(array('client_id' => 'YOUR-CLIENT-ID','client_secret' => 'YOUR-CLIENT-SECRET','grant_type' => 'client_credentials'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('POST / HTTP/1.1','Content-Type: application/json','Content-Length: '.strlen($json)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$raw = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
$response = json_decode($raw, true);
| improve this answer | |
0

The C# Fuel SDK has been updated to handle the new oAuth 2.0 process

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.