crisp-im / node-crisp-api

:zap: Crisp API Node Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
99 stars 39 forks source link

Error: restricted_route_tier #56

Closed jryebread closed 1 year ago

jryebread commented 1 year ago

Hi I'm trying to setup the onboarding flow for when a user subscribes their website to my new plugin.

  async updatePluginForWebsite(websiteId, token, botName, botId, live, apiKey) {
    // if (!this.websites[websiteId]) {
    //   console.error("Website does not exist! Retry with a valid websiteId.");
    //   return;
    // }

    console.log("UPDATING VALUE")

    if (!live) {
      console.log('unsubbing!')
      await this.crispClient.plugin.unsubscribePluginFromWebsite(websiteId, this._pluginId)
      return;
    }

    try {
      // Subscribe the user 
      await this.crispClient.plugin.subscribeWebsiteToPlugin(websiteId, this._pluginId);
      console.log("Subbed website to plugin!")
      await this.crispClient.plugin.updateSubscriptionSettings(
        websiteId,
        this.pluginId,
        { botId: botId, botName: botName, apiKey: apiKey }
      );

      this.websites[websiteId] = { botName: botName, botId: botId, apiKey: apiKey };

      console.log(
        `Successfully updated plugin config for website ID: ${websiteId}`
      );
    } catch (error) {
      console.error(`Failed to update plugin config for website ID: ${websiteId}. Error: ${error.message}`);
      throw error;
    }
  }

I created a new crisp app account to test out the production flow (my plugin is "activated" but set to private) when I click the install link and it calls the API "subscribeWebsiteToPlugin" I get this error:

Failed to update plugin config for website ID: bc20aeec-6395-48fc-aaf2-5623af9eab5eb. Error: restricted_route_tier

What does this error mean? I am authenticating the crispClient above with my prod token id and key and calling setTier with val "plugin"

// eg. this.crispClient.authenticateTier("7c3ef21c-xxx-5605c346f73e", "cc29e1a5086e428fcc6a6xxx7a66d82808e65c5cce006fbf2191ceea80a0a"); this.crispClient.setTier("user")

baptistejamin commented 1 year ago

Your plugin is in dev mode or production mode ?Sent from my iPhoneOn 29 Aug 2023, at 04:57, James @.***> wrote: Hi I'm trying to setup the onboarding flow for when a user subscribes their website to my new plugin. async updatePluginForWebsite(websiteId, token, botName, botId, live, apiKey) { // if (!this.websites[websiteId]) { // console.error("Website does not exist! Retry with a valid websiteId."); // return; // }

console.log("UPDATING VALUE")

if (!live) {
  console.log('unsubbing!')
  await this.crispClient.plugin.unsubscribePluginFromWebsite(websiteId, this._pluginId)
  return;
}

try {
  // Subscribe the user 
  await this.crispClient.plugin.subscribeWebsiteToPlugin(websiteId, this._pluginId);
  console.log("Subbed website to plugin!")
  await this.crispClient.plugin.updateSubscriptionSettings(
    websiteId,
    this.pluginId,
    { botId: botId, botName: botName, apiKey: apiKey }
  );

  this.websites[websiteId] = { botName: botName, botId: botId, apiKey: apiKey };

  console.log(
    `Successfully updated plugin config for website ID: ${websiteId}`
  );
} catch (error) {
  console.error(`Failed to update plugin config for website ID: ${websiteId}. Error: ${error.message}`);
  throw error;
}

}

I created a new crisp app account to test out the production flow (my plugin is "activated" but set to private) when I click the install link and it calls the API "subscribeWebsiteToPlugin" I get this error: Failed to update plugin config for website ID: bc20aeec-6395-48fc-aaf2-5623af9eab5eb. Error: restricted_route_tier What does this error mean? I am authenticating the crispClient above with my prod token id and key and calling setTier with val "plugin" // eg. this.crispClient.authenticateTier("7c3ef21c-xxx-5605c346f73e", "cc29e1a5086e428fcc6a6xxx7a66d82808e65c5cce006fbf2191ceea80a0a"); this.crispClient.setTier("plugin")

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

jryebread commented 1 year ago

production mode i think, it shows as private and "activated" under marketplace

baptistejamin commented 1 year ago

Check your tokens anyway :)Sent from my iPhoneOn 29 Aug 2023, at 23:29, James @.***> wrote: production mode i think, it shows as private and "activated" under marketplace

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

jryebread commented 1 year ago

its the production token im using for sure, the website does not say if the pulugin is in prod or dev mode, it just sais it is activated and "private"

jryebread commented 1 year ago

@baptistejamin

eliottvincent commented 1 year ago

Hey there! The errors means the tier is not allowed for the current API route. So you're either trying to hit a user-only API route with a plugin token, or a plugin-only API route with a user token.

Make sure to only hit plugin routes and use the correct identifier, key, and tier (plugin).

jryebread commented 1 year ago

hey thanks for your message this helped a lot, figured out subcribe/unsub api endpoints are only for user