Asana / java-asana

Official Java client library for the Asana API v1
MIT License
35 stars 42 forks source link

Incorrect implementation of updateTeam() #158

Open takraj opened 2 years ago

takraj commented 2 years ago

Hi,

I'm using version 1.0.0 of this library from Maven Central: https://mvnrepository.com/artifact/com.asana/asana/1.0.0 This is the latest version by the time of creating this ticket.

The current implementation of updating a Team calls the /teams endpoint: https://github.com/Asana/java-asana/blob/d7281b00d29b279e835c0f3f073f1819463e28d9/src/main/java/com/asana/resources/gen/TeamsBase.java#L181

This is also conform with the documentation: https://developers.asana.com/docs/update-a-team

However, if I attempt to call this API via curl, I always get the HTTP 404 error.

Example:

curl -v -X PUT https://app.asana.com/api/1.0/teams -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: *****' -d '{"data": {"name":"abc","organization":"1203195973075798","description":"Lorem Ipsum"}}'

I also get the same error message, when I attempt to use the client library.

However, if I add the team ID to the URL, then I can successfully update it.

Example:

curl -v -X PUT https://app.asana.com/api/1.0/teams/1203218620623147 -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: *****' -d '{"data": {"name":"abc","organization":"1203195973075798","description":"Lorem Ipsum"}}'

So this seems to be an error to be corrected both in the docs and the client.

I could work it around by this class:

public class CorrectedTeams extends TeamsBase {

        public CorrectedTeams(Client client) {
            super(client);
        }

        public ItemRequest<Team> updateTeam(String team)
                throws IOException {
            String path = format("/teams/%s", team);

            return new ItemRequest<Team>(this, Team.class, path, "PUT")
                    .query("opt_pretty", null)
                    .query("opt_fields", null)
                    .query("limit", (int) Client.DEFAULTS.get("page_size"))
                    .query("offset", null);
        }
    }