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

type 'Null' is not a subtype of type 'int' when using queryParameters #79

Open
mihaiicey opened this issue Nov 18, 2024 · 1 comment
Open

Comments

@mihaiicey
Copy link

Hi,
I didn't find exactly in the documentation the query params part...
I get error: Error fetching data: type 'Null' is not a subtype of type 'int'

when I do the last query like:

final request = RetrievePageRequest(
  id: 579,
  queryParameters: {
    'acf_format': 'standard',
    '_fields': 'acf',
  },
);

it's a problem with "_fields"...i've tested in postman an there it works.

@ArunPrakashG
Copy link
Owner

ArunPrakashG commented Dec 7, 2024

Hi @mihaiicey , apologies for the late reply.

I believe this issue occurs because some of the fields in the response model we have currently is not nullable. for example, the id field.

To overcome this, we have a raw request system in the library. Every operation (list, retrieve, get, delete etc) has their equivalent raw operation. you can invoke these by adding raw to the end of the method name. (listRaw, retrieveRaw, etc)

This will skip the model parsing on the library and give the full raw response from the API. Your updated code will be:

final result = await client.pages.retrieveRaw(
    RetrievePageRequest(
      id: 579,
      queryParameters: {
        'acf_format': 'standard',
        '_fields': 'acf',
      },
    ),
  );

final acf = result["acf"];

or to get the acf object safely (no exceptions, nullable, with optional transforming), use result.getField(...)

And yes, the result object is of type WordpressRawResponse it contains all the details you need about the response from the server.

Let me know if you need further help on this.

Read more on this here.

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