Skip to content

How to expand GET company with orders #136

Closed as not planned
Closed as not planned
@fxmb

Description

@fxmb

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions