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

How to expand GET company with orders #136

Open
fxmb opened this issue Dec 18, 2024 · 0 comments
Open

How to expand GET company with orders #136

fxmb opened this issue Dec 18, 2024 · 0 comments
Assignees

Comments

@fxmb
Copy link

fxmb commented Dec 18, 2024

I want to expand the retrieveCompany() method to attach an array of all orders as well.

It should be extremely straight forward but I simply cannot get it to work.

When I add the *orders like below to fetch orders as well the validator on the server keeps complaining:

error: Requested fields [orders] are not valid

I have added it to the validator though like so:

export const storeCompanyFields = [
  "id",
  "name",
  "logo_url",
  "email",
  "phone",
  "address",
  "city",
  "state",
  "zip",
  "country",
  "currency_code",
  "*employees",
  "*orders",
];
export const retrieveCompany = async (companyId: string) => {
  const headers = {
    ...(await getAuthHeaders()),
  }

  const next = {
    ...(await getCacheOptions("companies")),
  }

  const company = await sdk.client.fetch<StoreCompanyResponse>(
    `/store/companies/${companyId}`,
    {
      query: {
        fields:
          "+spending_limit_reset_frequency,*employees.customer,*invites,*orders",
      },
      method: "GET",
      headers,
      next,
    }
  )

  return company
}

Does anyone have a working example of how to expand the companies endpoint to fetch an array of all orders that company placed?

@VariableVic VariableVic self-assigned this Dec 19, 2024
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