I try to get acces token from the zoom api with a post request but i don't understand why i have this error:
reason: 'Invalid client_id or client_secret',
error: 'invalid_client'
My code :
let clientID = "exemple"
let clientSecret = "exemple";
const zoomtokenep = "https://zoom.us/oauth/token";
const myappredirect = "http://localhost:3000/campaigns";
let url = zoomtokenep + "?grant_type=authorization_code&code=" + "code_exemple" +
"&redirect_uri=" + myappredirect;
let auth = "Basic " + new Buffer(clientID + ':' + clientSecret).toString('base64');
await axios({
method: "POST",
url: url,
headers: {
"Autorization": auth,
},
})
.then(res => console.log(res))
.catch(err => console.error(err));
Related
I want to automate the api using Cypress, but I can't access the response body.
Use this path cy.log(JSON.stringify(response.body.payload[0]
Api Response
Code
context('GET /Auth', () => {
it('should return a list with all products', () => {
cy.request({
method: 'GET',
url: 'https://auth.plus.a101.com.tr/api/homepage/punch-cards/20149126',
headers: {
'Authorization' : 'Bearer ' + access_token
}
})
.then((response) => {
expect(response.status).to.eq(200)
cy.log(JSON.stringify(response.body.payload[0]))
});
});
});
I get error
You have to convert your response object a json string and then parse it. Instead you can try the following:
cy.request({
method: 'GET',
url: 'https://auth.plus.a101.com.tr/api/homepage/punch-cards/20149126',
headers: {
'Authorization' : 'Bearer ' + access_token
}
}).then((response) => {
response = JSON.stringify(response)
var jsonData = JSON.parse(response)
cy.log(response.body.payload[0])
});
I'm trying to make my API request wait for API response, i did this:
export async function foldercreator(language,date){
const paths = ["" ,"/" + language , "/" + language + "/" + "/kanban","/" + language + "/" + "/LavagnaFornitore", "/" + language + "/" + "/LavagnaPianificatore"];
for(let i=0; i<paths.length; i++){
var request = await require('request');
var options = {
'method': 'MKCOL',
'url': "****"
'headers': {
'Authorization': 'Basic *******',
},
};
await request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
}
Because you don't have async function
i've been trying to get some data from the non pro CB via their API.
I've been able to get data from coinbase pro, with the code below, adding the passphrase, but no dice with CB...
I keep getting invalid signature :(
Any idea what i could be missing?
const signedMessages = async (timestamp, meth, requestPath) => {
const secret = process.env.cb_all_read_secret;
const method = meth.toUpperCase();
const body = '';
const message = timestamp + method + requestPath + body;
const key = Buffer.from(secret, 'base64');
const hmac = crypto.createHmac('sha256', key);
const cb_access_sign = hmac.update(message).digest('base64');
return cb_access_sign;
};
const listAccounts = async () => {
let timestamp = Math.floor(Date.now() / 1000);
const signed = await signedMessages(timestamp, 'GET', '/v2/accounts');
const url = 'https://api.coinbase.com/v2/accounts';
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'CB-ACCESS-KEY': process.env.cb_all_read_key,
'CB-ACCESS-SIGN': signed,
'CB-ACCESS-TIMESTAMP': timestamp,
},
};
console.log(options);
try {
const data = await fetch(url, options);
const resultat = await data.json();
console.log(resultat);
} catch (error) {
console.log('error: ', error.message);
}
};
listAccounts();
First thing I'd check is that your computer's clock is up to date i.e. not > 30 seconds behind the API server.
coinbase documentation is frustrating at best.
In one place I saw the method you're using being documented.
var what = timestamp + method + requestPath + body;
// decode the base64 secret
var key = Buffer(secret, 'base64');
// create a sha256 hmac with the secret
var hmac = crypto.createHmac('sha256', key);
// sign the require message with the hmac
// and finally base64 encode the result
return hmac.update(what).digest('base64');
When I went to find it again I found the following: documentation which does the signing a little differently:
var signature = crypto.createHmac("sha256", apiSecret).update(message).digest("hex");
Notice the lack of a base64 buffer and the digest is Hex.
I modified your code and was able to get the wallets with view permissions. I would probably create a sign function using the code in the link provided including the body for any options you need to include.
const signedMessages = async (timestamp, method, path) => {
const apiSecret = '...';
const bodyStr = '';
let message = timestamp + method.toUpperCase() + '/v2/' + path + bodyStr;
return crypto.createHmac('sha256', apiSecret).update(message).digest('hex');
};
const listAccounts = async () => {
let timestamp = Math.floor(Date.now() / 1000);
const signed = await signedMessages(timestamp, 'GET', 'accounts');
const url = 'https://api.coinbase.com/v2/accounts/';
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'CB-ACCESS-KEY': '...',
'CB-ACCESS-SIGN': signed,
'CB-ACCESS-TIMESTAMP': timestamp,
},
};
console.log(options);
try {
const data = await fetch(url, options);
const resultat = await data.json();
console.log(resultat);
} catch (error) {
console.log('error: ', error.message);
}
};
listAccounts();
but guess what...
the "deprecated" node api does it the same way (that's where I found this signing method before I found the documentation) and it was last updated 4 years ago. Go figure.
I created a front end application on vue.js and I use phoenix as backend.
I try to make a request and returns an error :
GET http://localhost:4000/api/v1/my_user 401 (Unauthorized)
it's better than having CORS issue.
In my script part, I build my header to manage access control and pass Authorization. At the end, I call my URL and pass variables.
getCurrentUser: function() {
let axiosConfig = {
headers: {
"Content-Type": "application/json;charset=UTF-8",
"Access-Control-Allow-Origin": "*",
"Authorization": "Bearer " + localStorage.getItem("jwt")
}
};
// call rest API
axios
.get("http://localhost:4000/api/v1/my_user", {}, axiosConfig)
.then(res => {
console.log("RESPONSE RECEIVED: ", res);
//const jwt = res.data.jwt;
//this.showComponent = false;
console.log("res:" + res);
//localStorage.setItem("jwt", jwt); // store the token in localstorage
})
.catch(err => {
console.log("AXIOS ERROR: ", err);
});
},
localStorage.getItem("jwt") returns the correct token.
My issue is that i don't meet error by using postman client and when i pass as Authorization value the same values as in the header / Authorization
I replaced this code by :
getCurrentUser: function() {
axios.defaults.headers.common["Authorization"] =
"Bearer " + localStorage.getItem("jwt");
// call rest API
axios
.get("http://localhost:4000/api/v1/my_user")
.then(res => {
console.log("RESPONSE RECEIVED: ", res);
})
.catch(err => {
console.log("AXIOS ERROR: ", err);
});
},
I am using Firebase Cloud Functions for push notification when onCreate. Please help.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref('/messages/diyetisyen/{uname}/{msgid}/message')
.onCreate((snapshot, context) => {
let message = snapshot.val();
let uname = context.params.uname;
//let uname_slice = uname.slice(0,(uname.length-4)) + uname.slice((uname.length-3));
let root = snapshot.ref.root;
let tokenRef = root.child('/users/' + uname + '/token').ref;
let payload = {
data: {
custom_notification: JSON.stringify({
body: message + 'a',
title: 'title'
})
}
};
let options = { priority: "high" };
return tokenRef.once('value')
.then(dataSnapshot => {
let token = dataSnapshot.val();
console.log('2 \n'+'message \n' + message +'\n tokenref \n' + tokenRef +'\n token \n' + token +'\n uname \n' + uname+'\n gönderiliyor');
return admin.messaging().sendToDevice(token, payload, options);
});
});
I am getting message, token ,uname correctly but admin.messaging().sendToDevice(token, payload, options); not working.
I changed payload like
const payload = {
notification: {
title: 'title',
body: message + ''
}
};
and it's working.