Back

[SOLVED] Create User Target unexpectedly fails.

  • 0
  • Functions
  • Messaging
  • Cloud
Mark.R.
7 May, 2024, 07:35

New to AppWrite and first post here on Discord. Hello all.πŸ˜€

I am having some issues understanding why my call to users.createTarget() fails in a function. (https://appwrite.io/docs/references/cloud/server-nodejs/users#createTarget).

I have the following code excerpt that works fine when being called from a node server app communicating with a self-hosted appwrite:

TypeScript
  \\
  \\ imports, client setup, other code
  \\
    try {
    const result = await users.createTarget(
      deviceID,   // userId - we use the device identifier as the user token
      targetID,   // targetId - //Choose a custom ID or generate a random ID with ID.unique()
      'push',     // providerType
      apnsToken   // identifier - the apns token
      //'',       // providerId (optional) - will use the first push provider if not explictly set
      //''        // name (optional)
    )
    return res.json({
      "success" : "token associated with device"
    })
  } catch(targetError) {
      error(`failed to create target ${targetError}`)
      return res.json({ "error": `unable to associate token` }, 400)
  }

However, when I run this in a cloud hosted function, I get the error logged in the in the console: failed to create target TypeError: users.createTarget is not a function.

I am using the appwrite.io (cloud) to host the function.

The documentation online seems to suggest that this should be available in the cloud node-appwrite sdk?? Any suggestions?

TL;DR
Issue: Developer experiences a problem with `users.createTarget()` function, which works fine on a self-hosted server but fails on a cloud-hosted function. Solution: Clear npm cache and pull the latest version to fix the issue. The problem may arise due to using an earlier version of node-appwrite on the cloud.
darShan
7 May, 2024, 07:43

What version of the sdk are you using?

Mark.R.
7 May, 2024, 07:49

Aaah .. it may be that simple!! I used the starter template on both self-hosted server and cloud - but now realise that the starter template on the cloud uses an earlier version of node-appwrite.

darShan
7 May, 2024, 07:50

haha, no worries. make sure to clear npm cache and pull the latest version. that should fix the issue.

Mark.R.
7 May, 2024, 07:50

thank you very much. will do!

darShan
7 May, 2024, 07:51

please mark you issue as [SOLVED] once its resolved. If you encounter any other errors, feel free to create another thread or continue in this one.

Happy Appwriting :appwritecheers:.

Mark.R.
7 May, 2024, 07:51

[SOLVED]

darShan
7 May, 2024, 07:55

hey πŸ‘‹, could you please add [SOLVED] as the prefix to the post title so that its pretty visible outside the thread too πŸ˜…. thnx.

Mark.R.
7 May, 2024, 07:55

[solved] Create User Target unexpectedly fails.

Mark.R.
7 May, 2024, 07:56

[SOLVED] Create User Target unexpectedly fails.

Mark.R.
7 May, 2024, 07:56

Cheers. NOOB.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more