How to get by UID without defining the Page Type?

Svelte/Sveltekit project

I've the following URL structure: .com/apps/[uid]/[uid]

So it's going to have:

  • apps/hubspot/integration-with-zapier
  • apps/hubspot/error-when-syncing-contacts

The first one is of type Integration, and the Second one is of type Errors.

When querying, I've to query with,

client.getByUid('errors', params.uid)

But then my URL structures goes to :toilet:because now I've to specify the page type in the request, so the URL must also contain that information.

What would be the best way to to get documents based solely on the UID?

Hey @aadtyaraj01,

This goes against our recommended implementation. We would always discourage users from putting two different types in the same route. I would probably make the routing structure:

  • app/hubspot/integration/zapier
  • app/hubspot/error/syncing-contacts

However, if that's not an option, there are some potential workarounds.

As you've observed, there is no way to query a document by its type without specifying the UID.

The most obvious workaround in my mind would be to use a try/catch block (untested code):

async function attemptQuery(uid) {
  try {
    return await client.getByUID("error", uid)
  } catch (error) {
    null
  }
  try {
    return await client.getByUID("integration", uid)
  } catch (error) {
    null
  }
}

There's probably a better way to structure this so that you can still catch the error message if its an unexpected error, but this might give you some idea as to how to proceed.

What do you think? Would this help with your use case?

Sam

This seems like a doable workaround for my simple usecase. Thanks. Are there any pitfalls or performance implications that i should know about in this case?

Hey @aadtyaraj01,

Yes, I imagine that this will have some performance costs, and it will increase your API usage. However, I can't say exactly what the effect will be since I've never tried it myself.

Sam