Permission error when trying to retrieve templates using API



3 - Onboarding Teams - 2

Hello,
we are developing an integration between HubSpot and Asana using NodeJs
We start the test using a trial account (one workspace). The code below was working fine and we were able to retrieve templates using API:

async getTemplates( workspaces:Array<IAsanaBaseAnswer> ): Promise<Array<IAsanaBaseAnswer>> {
 let templates:Array<IAsanaBaseAnswer> = [];
 for (let i=0; i<workspaces.length; i++) {
  const foundTemplates = await this.getAllByGid<IAsanaBaseAnswer>(workspaces[i].gid, this.requestTemplates.bind(this));
  if (foundTemplates?.length) {
   templates = templates.concat(foundTemplates);
  } else {
   await this.teamService.setUser(this.user);
   const teams: Array<IAsanaBaseAnswer> = await this.teamService.getTeamsByWorkspace(workspaces[i].gid);
   for (let k=0; k<teams.length; k++) {
    const templatesByTeam: Array<IAsanaBaseAnswer> = await this.getAllByGid<IAsanaBaseAnswer>(teams[i].gid, this.requestTemplatesByTeam.bind(this));
    if (templatesByTeam?.length) {
     templates = templates.concat(templatesByTeam);
    }
   }
  }
 }
 return templates.filter((el:IAsanaBaseAnswer, index:number, self:IAsanaBaseAnswer[]) =>
  self.map((v:IAsanaBaseAnswer) => v.gid).indexOf(el.gid) === index
 );
}

Then we started having clients who have organizations instead of one workspace. Unfortunately, the same code is not working.

I’m Admin on my account and I have all permissions. Everything seems OK but we are getting this error message:

{"errors":[{"message":"workspace: Not a valid regular workspace. You provided an organization. Check out https://asana.com/developers/api-reference/workspaces for the difference between workspaces and organizations.","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}

Could you please help?

Thank you in advance.
Lamine

I don’t know if this helps but workspaces don’t have teams…

So I guess your call to get the teams is not necessary when its a workspace and potentially you can request the templates directly using a workspace id.

Hi Bastien.
Thank you for your reply.

I know that workspaces don’t have teams.

When we didn’t have workspaces, with the above code we could retrieve templates without any permissions issues.

Now we have organizations with teams, I’m the admin of the account and I’m a member of all teams but I can’t retrieve templates.

any idea why I’m having this permission error message:

{"errors":[{"message":"workspace: Not a valid regular workspace. You provided an organization. Check out https://asana.com/developers/api-reference/workspaces for the difference between workspaces and organizations.","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}

It’s an app that will be sold on the HubSpot marketplace. We are dealing with clients with organizations and clients with workspaces.

We need to take into consideration both cases.

I might know why: to get templates now, you need to ask them one team at a time, you can’t get all templates at once anymore.

1 Like

We could resolve the issue.

The issue wasn’t in the code. Asana changed their SDK and we didn’t notice it.

@Bastien_Siebman Thank you for your help

Regards
Lamine

1 Like