Open zhamid-src opened 4 years ago
FYI, I posted a simpler version. "return await" was there because this was initially wrapped in a try / catch block. I simplified the example to create the minimum code that reproduces the problem.
I changed the code to manually making the GET call for testing :-
export async function eeAccountAddSubaccount(email: string) {
const url = `${EEOptions.apiUri}${EEOptions.apiVersion}/account/addsubaccount?apiKey=${EEOptions.apiKey}&email=${email}&password=placeHolderPassw0rd&confirmPassword=placeHolderPassw0rd`;
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
return axios({
method: 'GET',
url: url,
headers: headers
});
This works. This indicates that the problem is the new JavaScript API and not my code.
@zhamid-src no, your code is using GET: We just tested the call with the following example:
const options = {
apiKey: "secretapikey",
apiUri: 'https://api.elasticemail.com/',
apiVersion: 'v2'
}
const EE = new EEAPI.client(options);
EE.Account.Load().then(function(resp) {
console.log(resp);
})
.catch((err) => {
console.log(err)
});
async function addSubAccount(params) {
return await EE.Account.AddSubAccount(params).catch((err) => console.error('error from elasticEmail: ', err));
}
const params = {
email: 'yourtestemail1@gmail.com',
password: 'foo123',
confirmPassword: 'foo123'
}
console.log(addSubAccount(params).then(resp => {console.log(resp)}));
and this works perfectly fine
GET call worked (POST works too) because I did it manually. Depending on the parameters, the EE.Account.AddSubAccount call can fail when same parameters pass with me calling axios directly. That leads me to believe that it has to do with the way your API is creating form data, which shouldn't be necessary because axios handles it.
This call that was working perfectly fine, now fails.
The call fails with an undefined error. For the same reason,
EE.Account.GetSubAccountApiKey
fails as well, which pretty much prevents me from doing any operation.This is a blocking isue.