Generate JWT token programmatically "Reactor API" | Community
Skip to main content
Level 2
February 4, 2023
Solved

Generate JWT token programmatically "Reactor API"

  • February 4, 2023
  • 1 reply
  • 1957 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mahmoud-Majid

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.

 

 

 

1 reply

Stewart_Schilling
Community Advisor
Community Advisor
February 9, 2023

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.

Mahmoud-MajidAuthorAccepted solution
Level 2
February 9, 2023

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.

 

 

 

Stewart_Schilling
Community Advisor
Community Advisor
February 9, 2023

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); }