Can't set customField option to form to "currency" via API

Hello there, I seem to be having problems setting a customFields format to currency with the API. I have tried two different methods to no avail.

The first method I have used is using node-fetch in my express server to hit the custom_fields route with a POST request.

  const newField = {
      data: {
        currency_code: "EUR",
        format: "currency",
        name: "Price",
        precision: 2,
        resource_subtype: "number",
        enabled: true,
        workspace: `${process.env.workspaceGID}`,
      },
    };
    try {
      const response = await fetch(
        `https://app.asana.com/api/1.0/custom_fields`,
        {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${process.env.PERSONAL_ACCESS_TOKEN}`,
          },
          body: JSON.stringify(newField),
        }
      );
      const data = await response.json();
      //console.log(data);
      res.status(201).json(data);
    } catch (err) {
      console.error(err);
      res.status(400).json(err);
    }

And I have tried using the asana npm package to no avail.

  const client = asana.Client.create().useAccessToken(
    process.env.PERSONAL_ACCESS_TOKEN
  );
  client.customFields
    .createCustomField({
      currency_code: "EUR",
      enabled: true,
      format: "currency",
      name: "Price",
      precision: 2,
      resource_subtype: "number",
      workspace: `${process.env.workspaceGID}`,
    })
    .then((result) => {
      console.log(result);
      res.json(result);
    })
    .catch((err) => {
      res.json(err);
    });
});

In both situations I am successfully creating the custom_field of type number, but the format it is given is “Number” and I have to manually set it to the currency I want. Not sure if this is related but I also seem to have problems setting it’s format to “custom” and taking advantage of the custom_label and custom_label position options as well. Is there something basic I am missing here?

If I were you I would re-read the doc just in case (Asana), I would try the request with Postman and if it works I would investigate by logging what the library code does. Maybe they forgot to map those fields when data is sent to the server.

If that is indeed the case, you can always use the dispatcher available in the client library to do custom calls while being able to use the authentication layer. Let me know if you want an example.

Hope this helps.

1 Like

Thank you, this does help. I will try your suggestion and get back to you, thank you for your response!

Hey there! If you have the time I would appreciate an example. I have tried with a CURL request, also in postman and that gives me the same result. I even filtered my get request to only include the format field and it still gives me “none”, unless I go into asana and change it directly. Then I get a format of “currency”. I have tried using the update endpoint and when I update both the name and the format only the name goes through so I know am formatting my request correctly. I also get a 200, but still no changes. There seems to be several fields that I can’t change with the api, only manually such as format, number_value, text_value or custom_labels.

I have looked through the github and am getting a little lost reading through the code, although I am confused as to why the dispatcher would work and not hitting the endpoint directly with postman/curl? Isn’t the dispatcher also hitting the same endpoint?

Thanks in advance.

The dispatcher is definitely hitting the same endpoint, but might be structuring the params in a different way. For example, with GET you have inline params, with POST you have a body, maybe you mixed things up with postman?

I don’t have an example to share sorry, feel free to email me (bastien@ido-clarity.com) to discuss a potential dedicated help!