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

Blog Post API not supporting all the filters #7

Open
mehran-dabi opened this issue Dec 9, 2022 · 1 comment
Open

Blog Post API not supporting all the filters #7

mehran-dabi opened this issue Dec 9, 2022 · 1 comment

Comments

@mehran-dabi
Copy link

I'm trying to use the GetPage API in the BlogPostsAPI, but it only supports the date-related criteria, while in the HubSpot documentation here, The document mentions we can filter all of the fields. Like language__eq=en, that results in blogs with only language=en.

@clarkmcc
Copy link
Owner

The API clients in this package are generated directly from the Hubspot openapi spec. If there's not a filter in the code, that's because there's not a filter defined in the spec.

It looks like Hubspot lets you filter on any field as you noted, and has opted not to represent this in the spec. Two approaches we could take on this one:

Customize HTTP request with function options
One approach is to allow you to modify the HTTP request prior to sending it to the HTTP client. That would require a pretty big set of changes to function signatures from

func (a *BlogPostsApiService) GetPageExecute(r ApiGetPageRequest)

to something like this

func (a *BlogPostsApiService) GetPageExecute(r ApiGetPageRequest, options ...func(*http.Request))

and then you could apply the filters against a reference to the HTTP request. I'm not sure what kind of time I'd have to implement this in the short term, but would be happy to discuss this option and other alternatives in more depth with anyone else who would be interested in helping me implement it.

Use alternative openapi generators that support this behavior
I think that oapi-codegen might support this, but would need to investigate more to be sure. The downside to this approach is it would entirely change the current API of the generated clients.

Very bad, temporary workaround

type TransportFunc func(r *http.Request) (*http.Response, error)

func (f TransportFunc) RoundTrip(r *http.Request) (*http.Response, error) {
    return f(r)
}

c := blog_posts.NewAPIClient(&blog_posts.Configuration{
	HTTPClient: &http.Client{
		Transport: TransportFunc(func(r *http.Request) (*http.Response, error) {
			if strings.Contains(r.URL.Path, "/cms/v3/blogs/posts") {
				// Modify the query string with the language filter
			}
			return http.DefaultTransport.RoundTrip(r)
		}),
	},
})

c.BlogPostsApi.GetPage(context.Background()).Execute()

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

No branches or pull requests

2 participants