InvalidToken: De-serialization error -- POSTMAN - json

I use fabric Kony and I have given to Postman Username pass of Fabric to authenticate
enter image description here
and entered this prerequest script:
const postRequest = {
url: 'https://sandbox-api.marqeta.com/v3/swagger.json',
method: 'POST',
timeout: 0,
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "password"},
{key:"username", value: "........."},
{key:"password", value: ".........."},
]}
};
pm.sendRequest(postRequest, function (err, res) {
var responseJson = res.json();
console.log(responseJson);
pm.environment.set('ACCESS_TOKEN', responseJson['access_token']);
});

I'm not an user of POSTMAN, but I know a little of Kony Fabric.
If you hit the web url of a Kony Fabric you'll notice that the first call will generate an oauth_token (for example 0526b30c-6579-4965-a774-87224815ea3a) that will be used for further calls.
I think that you should catch this token before trying to connect to the Kony Fabric with a user's credentials.
Cordially,
Hervé N.

Related

Autodesk - Unable to upload images to Photo scene

I am having issues with sending files to the endpoint: https://developer.api.autodesk.com/photo-to-3d/v1/file
Once I receive the Auth token, I successfully create a Photo Scene with: https://developer.api.autodesk.com/photo-to-3d/v1/photoscene.
Then I also check, if the Photo scene is indeed created by calling the: https://developer.api.autodesk.com/photo-to-3d/v1/photoscene/${photosceneid}/properties.
If that goes through, I send the image files, which I first upload to a storage server
(because sending the files directly didnt work) and then I run:
let image_urls = await temporary_image_upload(files, photosceneid)
const form_data = new FormData();
form_data.append("photosceneid", photosceneid)
form_data.append("type", "image")
image_urls.forEach(url => form_data.append("file", url))
// I also tried:
// image_urls.forEach((url, index) => form_data.append(`file[${index}]`, url))
// Upload photos
const { data } = await axios.post(
"https://developer.api.autodesk.com/photo-to-3d/v1/file",
form_data,
{ headers }
)
//
//
// I also tried adding it as query params:
image_urls = image_urls.map((url, index) => `file[${index}]=${url}`).join("&")
// Upload photos
const { data } = await axios.post(
"https://developer.api.autodesk.com/photo-to-3d/v1/file",
`photosceneid=${photosceneid}&type=image&${image_urls}`,
{ headers }
)
But nothing seems to work and I get response:
{
Usage: '0.47925591468811',
Resource: '/file',
Error: {
code: '19',
msg: "Specified Photoscene ID doesn't exist in the database"
}
}
So I am not sure what might be wrong, since I can clearly verify that the Photo Scene has been created.
Could you please provide some support, been struggling with this for a few days now.
As you mentioned you can clearly confirm the photosceneid exists, I would suspect that your axios request is not as expected, maybe add details about your header. Here is a sample:
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + access_token
},
data: querystring.stringify({
photosceneid: photosceneId,
type: 'image',
'file[0]': 'https://path/to/file.JPG'
})
})

How do I fix this JSON parsing issue?

I send data with fetch() in HTML to an express API, this is how it comes out in the req.body (I use body-parser)
{
'{"address":"a","town":"NYC","details":"a","appr":': { '"Car1"': '' }
}
it's all "stringy", as the only way I know to "parse it" to send it, is to send it with JSON.stringify. But, upon getting the info, it's "unparseable", JSON.parse errors with "unexpected string in JSON at position 62"
I send it like:
body: JSON.stringify({
address: address,
town: town,
details: details,
appr: apr,
}),
I've tried everything I know how to do to attempt to "make it a JSON" again, but nothing has worked.
1 - Don't forget to add header to fetch
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json' // => this is important
},
body: JSON.stringify(data)
});
2 - Don't forget to add this on express
app.use(bodyParser.json())
Note: If you are using Express v4.16.0 or newer you can use built-in middleware. Thanks to #Dov Rine
app.use(express.json());
3 - req.body will be available as object after this. You should not use JSON.parse(req.body) because body-parser does this for you.
let address = req.body.address;

How to use JWT to store data in NextAuth

I return the following JSON after confirming credentials:
{username: 'foo', name: 'bar', type: 123}
However, NextAuth does not allow me to store all the fields due to model limitations, so what it returns in JWT to client is:
{name: 'bar', email: null, image: null}
My [...nextauth].js setup is very basic:
providers: [
Providers.Credentials({
async authorize(credentials) {
const res = await fetch('http://localhost:3000/api/user', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'credentials': JSON.stringify(credentials)
}
})
const user = await res.json()
if (user && !user.message) {
return user
} else {
return null
}
}
})
],
The only solution I came up with is to fake email field with JSON string in which I can store everything I need:
{name: 'bar', email: "{username: 'foo', type: 123}", image: null}
How can I do it properly? I tried looking into custom models (https://next-auth.js.org/tutorials/typeorm-custom-models), but it seems to be only about databases, which is not my case since I use JWT for session storage.
Also what drawbacks I can encounter if I continue with my solution?
You will need to persist the additional info through callbacks, at first through JWT's callback and then Session's callback:
callbacks: {
async jwt(token, user, account, profile, isNewUser) {
// Since you are using Credentials' provider, the data you're persisting
// _should_ reside in the user here (as far as can I see, since I've just tested it out).
// This gets called whenever a JSON Web Token is created (once) or updated
if (user?.type) {
token.status = user.type
}
if (user?.username) {
token.username = user.username;
}
return token
},
async session(session, token) {
session.type = token.type;
session.username = token.username;
return session
}
}

How to call the API with dynamic url parameters based on number of id's using angular

I have the API from the backend and I need to call the API with id's changing dynamically.
ex API:
http://13.567.544/api/meters/start?id=m1 (for id 'm1')
and for m2
http://13.567.544/api/meters/start?id=m2 (for id 'm2') and so on.
How to call the above API with id's(m1,m2,m4,....) passing dynamically(pass ids dynamically in API),and I want the typescript and service code for the same. Also I want to check with the console if it is working or not in developer tools.
In
Postman, I received the following.
{
"status": true,
"action": "m1 meter started"
}
and for 'm4'
{
"status": true,
"action": "m4 meter started"
}
the 'm' values will be changed according to the server.
.service.ts
meterstart( token) {
let httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Token ' + token
}),
Params:new URLSearchParams({
'id':this.meters.name;
})
};
this.http.get(environment.apiUrl+'/api/meters/start'+this.id,httpOptions).subscribe(
(data:any)=>{
console.log(data);
}
.component.ts
jammerstop(){
this.data=JSON.parse(localStorage.getItem("data"));
console.log(data);
}
I want the hard code for the above component and service code for calling the API, because I have not involved in this scenario

Invalid parameter: JSON must contain an entry for 'default' or 'APNS_SANDBOX'. => APNS Error in Scala (lift framework)

I'm getting APN Invalid parameter: JSON must contain an entry for 'default' or 'APNS_SANDBOX'. the log is here
And the code block is here:
how to fix this? this is built in scala lift framework.
This is the example in javascript. In the same way, we have to use. Need to use cases for
1.APNS_SANDBOX
2.APNS
3.default
// Setup SNS Client
const snsClient = new SNS();
// whatever your full endpoint arn is. (from createPlatformEndpoint)
const endpointArn = 'arn:aws:sns:...';
// any extra data you want passed along with the message
const payload = {
someCustomKey: 'someCustomValue'
};
// send it
snsClient.publish({
TargetArn: endpointArn,
MessageStructure: 'json', // so we can put in a custom payload and message
Message: JSON.stringify({
default: `DEFAULT MESSAGE ${message}`,
APNS_SANDBOX: JSON.stringify({
aps: {
alert: `IOS Sandbox SPECIFIC MESSAGE ${message}`,
},
payload,
}),
APNS: JSON.stringify({
aps: {
alert: `IOS Prod SPECIFIC MESSAGE ${message}`,
},
payload,
}),
}),
}).promise().then(() => {
console.log('Notification sent!');
}).catch((err) => {
console.log('Failed to send with:', err);
});
Used this link for reference