Closed velara3 closed 8 months ago
The day before using the same credentials I was able to get the hello world sample to work. Today it does not work.
curl --request GET \
--url https://image.adobe.io/pie/psdService/hello \
--header "Authorization: Bearer abc" \
--header "x-api-key: xyz"
So I'm guessing the token expired?
I found in the examples code that looks like this:
const authDetails: string = await this.generateIMSToken(clientIdAndApiKey, clientSecret);
let authInfo = JSON.parse(authDetails);
console.log(authInfo)
But I get errors on this call as well. That function is here:
async generateIMSToken(clientId, clientToken): Promise<string> {
const request = require("request-promise");
const imsConfig = {
clientId: clientId,
clientSecret: clientToken,
};
const url = 'https://ims-na1.adobelogin.com/ims/token/v3';
const options = {
method: 'POST',
url: url,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
grant_type: 'client_credentials',
client_id: imsConfig.clientId,
client_secret: imsConfig.clientSecret,
scope: 'openid,AdobeID,read_organizations'
}
};
return new Promise((resolve, reject) => {
request(options, (err, res, body) => {
if(err || res.statusCode >= 400) {
reject( err || body )
}else{
resolve( body )
}
})
})
}
Welp, testing again and calling, generateIMSToken()
, that call seems be returning a result now when it wasn't before (I might have had incorrect login before).
So generate token is working. I'll use the new token on future calls and see if that works.
I don't know what the original error could be. It might be that the signed psd url was invalid and the sdk is passing that error on because I don't see a listing for 401
in the call to documentManifest().
Calling generateIMSToken() first fixes the issue...
// pseudo code
const imsOrgId = "";
const clientId = "";
const authDetails: string = await this.generateIMSToken(clientId clientSecret);
const authInfo = JSON.parse(authDetails);
const authToken = authInfo.access_token;
const client = await sdk.init(imsOrgId, clientId, authToken);
const documentManifest = await client.getDocumentManifest(url);
console.log(documentManifest.document); // document object
console.log(documentManifest.status); // succeeded
When following the examples the following code works but just now I'm getting back this error:
The error happens on the call to
getDocumentManifest()
Shouldn't the error occur when calling
client.init()
?Is there a way to tell if the token expired or if the token is not valid?
How long do tokens last? The getting started page says tokens are valid for one hour in part but 60 days in another part. Maybe it's two different things. See the text in the screen shot, "...it is good for 60 days":
I am able to call client.createCutout() and get a invalid input but not an 401. The call fails but it is not a 401 error.