Expand my Community achievements bar.

SOLVED

Generate JWT token programmatically "Reactor API"

Avatar

Level 2

Hi All,

I'm trying to generate an access token programmatically and followed the steps per the documentation here: https://experienceleague.adobe.com/docs/experience-platform/tags/api/getting-started.html?lang=en#:~...
But I'm getting a 503: Service Unavailable response!
Is it not available anymore, or I'm missing something? 

Thanks.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @Stewart_Schilling, thanks for your reply. 
Fortunately, the problem has been resolved, and the root reason was sending 'Content-Type: multipart/form-data' in the payload when the data sent in the body was already in the correct format (format-data). But the problem now is that I want to generate JWT automatically, such as giving an expired token and getting a new token instead, but this method needs sending a valid token to receive another valid token! So it's not that useful to me; have you tried or implemented something similar before?

Also, I'm using vanilla JS in the client side (Google Apps Script) to fetch the data.

 

 

 

View solution in original post

4 Replies

Avatar

Community Advisor

I have experience with this.  Can you share the api call info that is yielding a 503?   Maybe I can help you out?  Also, if you are using nodeJS, I can share some code that I use for JWT creation and exchange.

Avatar

Correct answer by
Level 2

Hi @Stewart_Schilling, thanks for your reply. 
Fortunately, the problem has been resolved, and the root reason was sending 'Content-Type: multipart/form-data' in the payload when the data sent in the body was already in the correct format (format-data). But the problem now is that I want to generate JWT automatically, such as giving an expired token and getting a new token instead, but this method needs sending a valid token to receive another valid token! So it's not that useful to me; have you tried or implemented something similar before?

Also, I'm using vanilla JS in the client side (Google Apps Script) to fetch the data.

 

 

 

Avatar

Community Advisor

Here's my code to create the JWT and get a bearer token.  You will probably need to change your metaScopes, but the rest should work as-is. 

 

const auth = require("@adobe/jwt-auth");

async function getToken() {
    let buff = Buffer.from(process.env.ADOBE_IO_PRIVATE_KEY, 'base64');
    let adobe_io_private_key = buff.toString('ascii');

    const credentials = {
        clientId: `${process.env.ADOBE_IO_CLIENT_ID}`,
        technicalAccountId: `${process.env.ADOBE_IO_TECH_ACCOUNT_ID}`,
        orgId: `${process.env.ADOBE_IO_ORG_ID}`,
        clientSecret: `${process.env.ADOBE_IO_CLIENT_SECRET}`,
        metaScopes: "https://ims-na1.adobelogin.com/s/ent_reactor_sdk",
        privateKey: `${adobe_io_private_key}`
    }
    return await auth(credentials);
}