Error ACS API

Avatar

Avatar

1982luca

Avatar

1982luca

1982luca

31-01-2021

Hello everyone,

 

I am building a javascript client to trigger transactional messages. I am stuck to obtain access_token with this error

{"error":"invalid_client","error_description":"missing client_id parameter"}

but I set this in the cUrl. I am using XMLHttpRequest approach and set the cUrl call in the body.

xhr.send('curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "client_secret=xxxx" -F "client_id=xxxxx" -F" jwt_token=111111111111jVENjI5NDg2NTk4MDYwREQwQTQ5NUQ2MkBBZG9iZU9yZyIsInN1YiI6IkE3MkQ1OUZBNjAwQkU3QzQwQTQ5NUM0MEB0ZWNoYWNjdC5hZG9iZS5jb20iLCJodHRwczovL2ltcy1uYTEuYWRvYmVsb2dpbi5jb20vcy9lbnRfcmVhY3Rvcl9zZGsiOnRydWUsImF1ZCI6Imh0dHBzOi8vaW1zLW5hMS5hZG9iZWxvZ2luLmNvbS9jL2ZjYzNiYjcyODkxMDRmYmViNjdlZjljZjIzMmIwZDMzIn0.rNkFXFJChuslxMJenzWbRmDdG_JFIb4lWMsRrnhbhzaUfFw01sYGEy8aqWxwm7VnZfTsd9G9_QEbatsBhXIyDLGN4-DJGCsSy6PfU7jvZfMldMmeIMHAzuQ1p1wDlaVyeW7fKMhBa4_vG4P3SVu1sdM8IvFdKhD9jx8-T6uSvAea38VfrzWJ0hkEbP03_HNUaDzVGaIChUm3_X5f3QCZlg-kPaPQt0TovK7bW2IQbXJCuBxa6O3IOrktuRyfADDoX_ebA-bqSKPiEUjFjO1DiYRrx8HLWySRBglO8t3Zw15y-uYSHEPN8lf18oTEqZBVPyAckS57eWKr7M3G2wkRsg" "https://ims-na1.adobelogin.com/ims/exchange/jwt/" ');

any idea?

Thanks 

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar

DavidKangni

MVP

Avatar

DavidKangni

MVP

DavidKangni
MVP

01-02-2021

Contact Adobe support. They will provide you a python script to generate jwt token and you can call this script from your javascript

1982luca

Hi @DavidKangmi, I am using the jwt token has been generate in Adobe Console I/O with Curl command. By using this approach

 

const data = new FormData();

data.append("client_id", "xxxxxx");
data.append("client_secret", "xxxx");
data.append("jwt_token", "xxxxx");

const xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.open("POST", "https://ims-na1.adobelogin.com/ims/exchange/jwt/");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("Access-Control-Allow-Headers","Content-Type");
xhr.setRequestHeader("Access-Control-Allow-Origin","*");
xhr.setRequestHeader("Access-Control-Allow-Methods","POST");
xhr.setRequestHeader("Cache-Control","multipart/form-data");
xhr.send(data);
DavidKangni

Hi,

 

Your syntax looks good overall. Can you just move the client_id before the client_secret?

 Also sometimes you may need to play with the quotes/double quotes.

DavidKangni_0-1612354017516.png

Thanks,

David

1982luca
@DavidKangni, Iam able to execute the call by using
DavidKangni
Great to hear that you were able to execute the call. Please update the ticket to solve. Thanks
1982luca

@DavidKangni, now im using the token to trigger transactional message with the folwloing code

 

const data = {

"email": "lxxxx",
"ctx" :{
"lastName": 'Sammy',
"firstName": 'Sammy',
"apiKey": '111111'
}

};


xhr1.open("POST", "https://cors-anywhere.herokuapp.com/https://mc.adobe.io/xxxx-mkt-stage1/campaign/xx/EVENT");
xhr1.setRequestHeader("X-api-key","XXX");
xhr.setRequestHeader("Authorization", token);
xhr1.setRequestHeader("cache-Control", "no-cache");
xhr1.setRequestHeader("cache-Control", "application/json");

xhr1.send(JSON.stringify(data));

But I am gettting error the error below:

RST-360011 An error has occurred - please contact your administrator.
XTK-170019 Access denied.
Error while executing the method 'DispatchEvent' of service 'nms:rtEvent'.

I tried to add Bearer to use
xhr1.setRequestHeader("Authorization", "Bearer" +token) but it doesnt work.
Any idea?
DavidKangni

Hi Luca,

Below is sample code to sent transactional message from ACS. The only issue i'm seeing in your code is the URL you have 

https://cors-anywhere.herokuapp.com
-X POST https://mc.adobe.io/<ORGANIZATION>/campaign/mcAdobe/EVTcartAbandonment \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-H 'Cache-Control: no-cache' \
-H 'X-Api-Key: <API_KEY>' \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Content-Length:79'

{
  "email":"test@example.com",
  "scheduled":"2017-12-01 08:00:00.768Z",
  "expiration":"2017-12-31 08:00:00.768Z",
  "ctx":
  {
    "cartAmount": "$ 125",
    "lastProduct": "Leather motorbike jacket",
    "firstName": "Jack"
  }
}

 

1982luca

@DavidKangni, Thanks for your help. Basically I am trying to build an extension from in Adobe Launch will help to trigger transactional messages /update profile and so on. Now I am trying to use require(jwt-simple) library to encode the payload and get jwt_token but I need to make node.js module on client side. Any suggestion or previous experience with browserfy.

Refer to herouk, I used that because i am getting cors error. Any idea how to fix that?

DavidKangni

@1982luca 

here is a link where following samples (github) demonstrate JWT generation and exchanging it with Adobe IMS endpoint to retrieve an access token using Node js, Java, Python, .Net, etc.

Once you are able to generate your jwt, please check how to send transactional message using ACS.

 

Thanks,

David

1982luca

Hi DavidKangni,

Basically I cannot use node module in react (client) side, below you can see the error. I need to find a way of using node module.


launch-EN00000000000000000000000000000000.js:551 Error: Cannot resolve module "@adobe/jwt-auth".
at launch-EN00000000000000000000000000000000.js:3308
at module.exports (launch-EN00000000000000000000000000000000.js:544)
at launch-EN00000000000000000000000000000000.js:804
at launch-EN00000000000000000000000000000000.js:2651
at launch-EN00000000000000000000000000000000.js:2390
at launch-EN00000000000000000000000000000000.js:2689
at launch-EN00000000000000000000000000000000.js:2499
at launch-EN00000000000000000000000000000000.js:2764
at Array.forEach (<anonymous>)
at initRules (launch-EN00000000000000000000000000000000.js:2763)

Avatar

Avatar

mmbb110

Avatar

mmbb110

mmbb110

02-02-2021

@1982luc, I would recommend first trying the usual way of triggering an API call via postman, with access token generated via Adobe Io console, and required headers.