import wixFetch from 'wix-fetch';
import wixSecretsBackend from 'wix-secrets-backend';
export async function getToken() {
const id = await wixSecretsBackend.getSecret("client_id");
const asecret = await wixSecretsBackend.getSecret("client_secret");
const body = {
"grant_type": "client_credentials",
"client_id": id,
"client_secret": asecret
};
wixFetch.fetch("https:// someurl . com/v1/token", {
"method": "post",
"headers": {
"content-type":"application/json"
},
"body": body
})
.then( (httpResponse) => {
let bodyUsed = httpResponse.bodyUsed;
let statusText = httpResponse.statusText;
let headers = httpResponse.headers;
let url = httpResponse.url;
if (httpResponse.ok) {
return httpResponse.json();
}
else {
return Promise.reject("Fetch did not succeed");
}
})
.then( (json) => {
console.log(json.someKey);
} )
.catch( (err) => {
console.log(err);
} );
}
//ERROR : Type '{ grant_type: string; client_id: string; client_secret: string; }' is not assignable to type 'string'. It’s recommended you use a new variable, such as "let newVar = ..." to make sure that all code completion work correctly.
Can someone help me. I am having a hell of a time retrieving an access token from a 3rd party API I am trying to integrate. This is my backend function. I keep getting those ugly little red squiggled lines under “body” on line 21. I have included the error message in the code above. Anyone know how to fix this problem? I am using the code from the velo/wix documentation. Not sure why I can’t use the recommended code, replace the required information with what is needed for the API I am attempting to use, and it work as intended, but here we are. Any ideas?