Skip to main content
razai22062698
Level 2
Jun 13, 2017 9:10 AM UTC
Solved

DMP Trait via API

Hey Guys,

It's Raza from Bank of Montreal Canada, I am a part of Personalization team here. We are working on something and we need some help. Do anybody have idea about creating a DMP Trait using API. What are prerequisites and other things ?

As of current scenario I have created a tool to generate DMP ruleset and then we copy that ruleset and manually apply that to Adobe Audience Manager(AAM). And In a future iteration of this tool, i'd like to use the AAM APIs within tool to automatically create that rule in AAM once someone clicks the "generate button".  But first we need to investigate how to use the API

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
unnikrishnanv18Accepted solution
Adobe Employee
Jun 27, 2017 4:25 PM UTC

$base64_code = base64_encode($client_id.":".$client_secret);

$ch = curl_init();

$request_headers = array();

$request_headers[] = 'Content-Type: application/x-www-form-urlencoded';

$request_headers[] = 'Accept: application/json';

$request_headers[] = 'Authorization: Basic '.$base64_code;

$data_to_post = "grant_type=password&username=$username&password=$password";

curl_setopt($ch, CURLOPT_URL, "https://api.demdex.com/oauth/token");

curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_post);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

$res = json_decode($result,true);

$access_token = $res['access_token'];

21 replies

amanp44838318
Adobe Employee
Adobe Employee
Jun 19, 2017 4:57 PM UTC

Hi Raza,

Adding to what Devinder shared with you earlier... In case you are using Postman tool for making these requests, here is another thing to keep in mind: we get the following error message when we choose the “Authorization Type” as something other than “No Auth” (assuming that we enter the correct credentials – UN & password for Audience Manager).

So as step 1 in Postman, under "Authorization" tab, you should select "No Auth" as Type. See screenshot below.

And then under the tab "Header", for the key "Authorization" the value should be “Basic <base-64 clientID:clientSecret>”

If we select any other Type under tab "Authorization", I see that we get the following response. Is this the error you are getting too?

"{"error":"invalid_grant","error_description":"Bad credentials"}".

Translate
Adobe Employee
Jun 19, 2017 7:32 PM UTC

The auth token request needs to be made against https://api.demdex.com/oauth/token  if the user credentials are for the production account.

Translate
razai22062698
Level 2
Jun 20, 2017 9:59 AM UTC

Hey Aman,

I am not using any tool, I am just doing it via Javascript. I feel there is some cross domain issue.

Translate
razai22062698
Level 2
Jun 20, 2017 10:00 AM UTC

Hi Unni,

I have tried both beta and production site, still facing the same issue. I think this might be a cross domain issue as I am runnin code from a local file

Translate
razai22062698
Level 2
Jun 20, 2017 10:37 AM UTC

I am getting this : XMLHttpRequest cannot load https://api.demdex.com/oauth/token. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.

Translate
razai22062698
Level 2
Jun 21, 2017 9:53 AM UTC

I feel the problem is with requesting token using Javascript, because when I requested token using JSON client like Postman or ARC(Advance REST Client) It work successfully and I got the JSON response with Access Token. Do you have idea to get Token using Javascript or AJAX ?

Translate
Adobe Employee
Jun 21, 2017 11:02 AM UTC

Hey Razai,

I used a PHP script and was able to get an auth token by setting the mentioned headers. You'll need to check with your dev team to troubleshoot the custom jQuery script by comparing both the requests to identify which parameter or header is missing or wrongly set.

Cheers,

Unni

Translate
razai22062698
Level 2
Jun 27, 2017 1:22 PM UTC

Can you please share the code piece ?

Translate
unnikrishnanv18Adobe EmployeeAccepted solution
Adobe Employee
Jun 27, 2017 4:25 PM UTC

$base64_code = base64_encode($client_id.":".$client_secret);

$ch = curl_init();

$request_headers = array();

$request_headers[] = 'Content-Type: application/x-www-form-urlencoded';

$request_headers[] = 'Accept: application/json';

$request_headers[] = 'Authorization: Basic '.$base64_code;

$data_to_post = "grant_type=password&username=$username&password=$password";

curl_setopt($ch, CURLOPT_URL, "https://api.demdex.com/oauth/token");

curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_post);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

$res = json_decode($result,true);

$access_token = $res['access_token'];

Translate
Gaurang-1
Level 9
Jul 4, 2017 7:27 AM UTC

Hi Raza,

Did you get a solution to your query? if yes, can you mark a reply as the correct answer. Marking an answer as correct will help other community users as well.

Thanks,

Translate