Когда Content-Type — application/json, все работает как и ожидалось, и я могу успешно получить и установить токен. Вот рабочий скрипт для application/json:
Код: Выделить всё
const axios = require("axios");
const https = require("https");
const httpsAgent = new https.Agent({
rejectUnauthorized: false
});
var path = "https://private-api-dev.pre/internal/jwt/generate";
var headers = {
"Content-Type": "application/json",
"Cache-Control": "no-cache",
"client-id": "123-456-789",
"client-secret": "123456789"
};
var body = JSON.stringify({
subject: "est",
audience: "customers",
miscInformation: "testing"
});
const auth = await axios.post(path, body, {
headers,
httpsAgent
})
.then((response) => {
bru.setEnvVar("jwt_token_dev", response.data.jwt);
console.log("Fetched JWT Token:", response.data.jwt);
})
.catch((error) => {
console.error("Error fetching token:", error.message);
});
Код: Выделить всё
const qs = require('qs');
var headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Cache-Control": "no-cache",
"client-id": "123-456-789",
"client-secret": "123456789"
};
var body = qs.stringify({
subject: "est",
audience: "customers",
miscInformation: "testing"
});
const auth = await axios.post(path, body, {
headers,
httpsAgent
})
.then((response) => {
bru.setEnvVar("jwt_token_dev", response.data.jwt);
console.log("Fetched JWT Token:", response.data.jwt);
})
.catch((error) => {
console.error("Error fetching token:", error.message);
});
Я также пробовал:
Код: Выделить всё
const body = new URLSearchParams({
subject: "est",
audience: "customers",
miscInformation: "testing",
}).toString();
Код: Выделить всё
fetch(path, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"x-ibm-client-id": "client-id",
"x-ibm-client-secret": "client-secret",
},
body: new URLSearchParams({
subject: "est",
audience: "customers",
miscInformation: "testing",
}),
agent: httpsAgent,
})
Подробнее здесь: https://stackoverflow.com/questions/793 ... uno-script
Мобильная версия