Skip to main content
Solved

Upserting Account via SDK => Not Working

  • 25 June 2024
  • 2 replies
  • 43 views

Trying to upsert a front account using the sdk. Its (like most of the API I have to say extremely cumbersome).

 

This is my code snippet:

 

async function upsertFrontAccount(validatedAddress: any): Promise<any> {

try {

return await sdk.createAccount({

name: validatedAddress.company || "Unknown Company",

domains: :validatedAddress.emailDomain],

custom_fields: {

Adresse: validatedAddress.address,

PLZ: validatedAddress.zip,

Stadt: validatedAddress.city,

Land: validatedAddress.country || "Germany",

Umsatzsteuernummer: validatedAddress.vatId,

Website: validatedAddress.url,

},

});

} catch (error) {

console.log("ERROR ON UPDATE", error.res);

if (error.status === 409) {

try {

await sdk.updateAccount(

{

account_id: `alt:domain:${validatedAddress.emailDomain}`,

},

{

name: validatedAddress.company || "Unknown Company",

domains: :validatedAddress.emailDomain],

custom_fields: {

Adresse: validatedAddress.address,

PLZ: validatedAddress.zip,

Stadt: validatedAddress.city,

Land: validatedAddress.country || "Germany",

Umsatzsteuernummer: validatedAddress.vatId,

Website: validatedAddress.url,

},

}

);

} catch (error) {

console.log("ERROR ON UPDATE", error);

}

console.log("UPDATE", error.res.data);

return;

}

console.log("ERROR", error.status);

throw new Error(`Front SDK call failed: ${error.message}`);

}

}

 

 

In a nutshell:

The create() call fails if it exists with a 409 => conflict. In that case I want to update() the account using the updateAccount method and pass the email domain like so:

account_id: `alt:domain:${validatedAddress.emailDomain}`,

 

Now it always complains with a 404 - Not found

 

Does not make sense to me that first there is a conflict and then right after not found. I mean its either one or the other.

 

I suppose I pass the alt:domain incorrectly but to do not know how to proceed. Please help me here. 

 

Thanks

 

PS: Why does Front not have a single Upsert() method? Its incredibly annoying to create, then update in case of a duplicate error….

2 replies

Userlevel 3
Badge +8

Hi @josula

Thanks for reaching out! Due to the nature and specificity of this issue, I believe the best approach would be to reach out to our support team to enable them to take a closer look at personal account details and API logs for your account. 

This would allow the team to better investigate and review the errors that you are receiving back from the API. Unfortunately, we do not have access to this info within the community setting. 

Best, 
Justin 

Userlevel 3
Badge +8

Hi @josula

Jumping back in here since our team was able to locate the account and review the logs. It looks like the 404 errors are due to the request path including the account ID of acc_123, which does not exist. This is default account ID provided in our demo requests here and may have been copied into your code by accident. To correct this, you would need to provide a valid account ID in your request path (https://api2.frontapp.com/accounts/{account_id})

As for the 409 errors, they appear to be legitimate conflicts with existing account domains. 

Hopefully this adds the additional insight you need to get this working as expected. Please let us know if we can help with anything else! 

Best, 
Justin 

Reply