Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property ['getCustomFieldsForWorkspace' | 'getCustomFieldsForProject' | 'getCustomField'] of undefined #221

Open
eboody opened this issue Dec 6, 2020 · 4 comments

Comments

@eboody
Copy link

eboody commented Dec 6, 2020

Hey there!

For some reason, I'm not able to use the getCustomFieldsForWorkspace function to work for me.

Here is example-code that gives me the same error ↓

const toke = 'my-token';
const asana = require('asana');

const client = asana.Client.create().useAccessToken(token);

(async () => {
  const workspaces = await client.workspaces.getWorkspaces();
  const gu = workspaces.data[0];
  
  client.customfields.getCustomFieldsForWorkspace(gu.gid)
  .then(result => console.log(result))
  .catch(error => console.log(error));
}

And this is the error I get ↓

(node:1624) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getCustomFieldsForWorkspace' of undefined
    at /mnt/c/Users/ebood/GDrive/Code/GUnits Task Closer/Task Closer.js:12:23
(node:1624) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1624) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I used the client object to get the workspaces and it worked fine, so when the error says that client.customfields is undefined I'm left scratching my head as to why customfields is missing from clients.

I encounter the same issue when I try to do getCustomFieldsForProject as well as getCustomField with the relevant project gid and custom field gid, respectively.

I am however able to get the custom field objects using CURL, but id like to do it just with javascript.

Am I doing something wrong?

@eboody eboody closed this as completed Dec 7, 2020
@eboody eboody reopened this Dec 7, 2020
@eboody eboody changed the title Cannot read property 'getCustomFieldsForWorkspace' of undefined Cannot read property {'getCustomFieldsForWorkspace' | 'getCustomFieldsForProject' | 'getCustomField'} of undefined Dec 7, 2020
@eboody eboody changed the title Cannot read property {'getCustomFieldsForWorkspace' | 'getCustomFieldsForProject' | 'getCustomField'} of undefined Cannot read property ['getCustomFieldsForWorkspace' | 'getCustomFieldsForProject' | 'getCustomField'] of undefined Dec 7, 2020
@eboody
Copy link
Author

eboody commented Dec 7, 2020

I was able to get the data like this ↓ but my code would be a lot easier for me to read if I could do it with the pretty code laid out in the documentation.

    const token = 'my-token';
    
    //you'll have to get your project.gid
    const projectGid = project.gid;

    const axios = require('axios');

    const response = await axios({
        url: `https://app.asana.com/api/1.0/projects/${projectGid}/custom_field_settings`,
        method: 'get',
        headers: {
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
    const customFields = response.data.data;

@emptydriptray
Copy link

emptydriptray commented Dec 15, 2020

I have the same issue

1 similar comment
@diego-zz
Copy link

I have the same issue

@tkmorrison
Copy link

The documentation has a capitalization error "client.customFields" instead of "client.customfields" should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants