# Imposible to convert undefined to principal when trying to call a canister from backend

**URL:** <https://forum.dfinity.org/t/imposible-to-convert-undefined-to-principal-when-trying-to-call-a-canister-from-backend/24714>\
**Category:** Language Support\
**Tags:** Motoko, Wasm, Education\
**Created:** [November 15, 2023, 2:05pm UTC](https://forum.dfinity.org/t/imposible-to-convert-undefined-to-principal-when-trying-to-call-a-canister-from-backend/24714 "2023-11-15T14:05:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ishmael-Chepsoi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ishmael-chepsoi/32/13061_2.png) [@Ishmael-Chepsoi](https://forum.dfinity.org/u/Ishmael-Chepsoi)\
**Post date:** [November 15, 2023, 2:05pm UTC](https://forum.dfinity.org/t/imposible-to-convert-undefined-to-principal-when-trying-to-call-a-canister-from-backend/24714/1 "2023-11-15T14:05:48Z")

</div>

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/8/85ab5ca8549456b858a8aca938ecb1875347afb0.jpeg)

**here is my backend functional call:**

```
public query func getAllParties() : async [Text] {
    let parties = Iter.toArray(mapOfPartyListing.keys());
    return parties;
};

```

_ **Have imported this canister to the frontend as follows:** _

import { ElecureV1\_backend } from ‘@/declarations/ElecureV1\_backend’;

**and try to call the function:**

async function getTeams() {  
// try {  
const allParties = await ElecureV1\_backend.getAllParties();  
console.log(allParties);  
const allPartiesArray = Array.from(allParties);  
console.log(allPartiesArray);  
// } catch (error) {  
// console.error(error);  
// }  
}  
useEffect(() =\> {  
getTeams();  
}, );

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [November 16, 2023, 4:30pm UTC](https://forum.dfinity.org/t/imposible-to-convert-undefined-to-principal-when-trying-to-call-a-canister-from-backend/24714/2 "2023-11-16T16:30:35Z")

</div>

The declarations use `process.env` variables to load the canister ID depending on whether you are building for `local` network or `ic`. Check the variable names in `@/declarations/ElecureV1_backend` and try adding console logs to debug!

It will probably be something you can configure with Next.js to load the values from your `.env` file. Here’s a guide with an approach you may want to try: [Environmental Variables in Next.js with dotenv | by Deepak Surya | Courtly & Intrepid | Medium](https://medium.com/courtly-intrepid/environmental-variables-in-next-js-with-dotenv-599c5bbfdf74)
