cloudbees-oss / zendesk-java-client

A Java client library for interacting with Zendesk
https://developer.zendesk.com/rest_api/docs/api-clients/java#zendesk-java-client-by-cloudbees
Apache License 2.0
148 stars 249 forks source link

Error obtained when iterating articles: "You passed an invalid value for the sort_by attribute..." #681

Closed raducoravu closed 1 week ago

raducoravu commented 3 months ago

Describe the bug Using version "0.24.1" of the client with the method org.zendesk.client.v2.Zendesk.getArticles(Section) I get for certain repos this unhandled error thrown from the server side:

 org.zendesk.client.v2.ZendeskResponseException: HTTP/400: Bad Request - {"error":{"title":"Invalid attribute","message":"You passed an invalid value for the sort_by attribute. The endpoint must specify a locale in order to sort by title, recent user activity, or edited_at"}}
at org.zendesk.client.v2.Zendesk.complete(Zendesk.java:2683)
at org.zendesk.client.v2.Zendesk.access$1400(Zendesk.java:101)
at org.zendesk.client.v2.Zendesk$PagedIterable$PagedIterator.hasNext(Zendesk.java:2950)

To Reproduce I do not have access to the repo of the client who can reproduce this problem but other Zendesk libraries have encountered it in the past: https://support.zendesk.com/hc/es/community/posts/5609287554586-BUG-Get-articles-by-section-ID-requires-locale https://github.com/facetoe/zenpy/issues/331#issuecomment-492969409

Expected behavior The iteration of articles should work

Desktop (please complete the following information):

Ideally the org.zendesk.client.v2.Zendesk.tmpl(String) method should allow adding a suffix with "?locale=en-us" or "?sort_by=updated_at" necessary to bypass the problem.

github-actions[bot] commented 1 month ago

This issue/PR is stale because it has been opened 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

raducoravu commented 1 month ago

Anyone else experiencing the same problem using the APIs?

PierreBtz commented 1 week ago

Sorry for the delay @raducoravu.

According to the documentation:

{/locale} is required only for end users or anonymous users. Admins and agents can omit it.

So most likely, you are calling the API as an end user or an anonymous user. It seems there is a way to set the local in the default method but not for the search by section and categories.

I don't have a way to reproduce, so I blind added the two missing methods, can you please try and tell me if it fixes the issue?

(https://github.com/cloudbees-oss/zendesk-java-client/pull/701)

raducoravu commented 1 week ago

@PierreBtz Thanks for investing the time to look into this. This problem was initially reported by our clients who encountered it using our connector on top of the "zendesk-java-client" libraries to upload to their specific Zendesk repo, so it was not something I could reproduce. I will ask them again if they still have the problem, maybe as you say the credentials they provided were not the ones of an admin. I think you can close the issue for now.

PierreBtz commented 1 week ago

Unsure I understand, do you need me to add the two endpoints in #701 so that end users/anonymous users can use the API, or are you telling me only admins are supposed to use it and then you don't need those endpoints?

raducoravu commented 1 week ago

@PierreBtz as there are already methods like "org.zendesk.client.v2.Zendesk.getArticles(String locale)", I think it makes sense to add similar signatures to other methods which iterate articles (so what you added might be useful for others as well). But I will also suggest my clients to use for publishing accounts which have admin rights in order to bypass this problem for now.

PierreBtz commented 1 week ago

Great, thanks for the feedback, I'll merge the PR adding the two methods.