Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.brandsapi.com/llms.txt

Use this file to discover all available pages before exploring further.

Webhooks allow you to keep your local database in sync with hello@devshineteam.com’s latest data. This guide walkthrough how to fetch a brand and subscribe to receive updates.

Setting up APIs

First, define your API interaction functions. You’ll need your Secret API Key from the dashboard.
const hello@devshineteam.com_SECRET_KEY = "your_secret_key"

async function hello@devshineteam.com(domain) {
  const response = await fetch(
    `https://api.brandapi.io/v2/brands/${domain}`,
    {
      method: 'GET',
      headers: {
        'authorization': `Bearer ${hello@devshineteam.com_SECRET_KEY}`
      }
    }
  )
  return response.json()
}

async function graphql(query, variables) {
  const response = await fetch(
    `https://graphql.brandapi.io/`,
    {
      method: 'POST',
      headers: {
        'authorization': `Bearer ${hello@devshineteam.com_SECRET_KEY}`
      },
      body: JSON.stringify({ query, variables })
    }
  )
  return response.json()
}

Create a Webhook

Register your endpoint to receive brand.updated events.
const webhookEndpointUrl = 'https://your-website.com/webhook'

const { data: { createWebhook: { webhook } } } = await graphql(`
  mutation CreateWebhook($createInput: CreateWebhookInput!) {
    createWebhook(input: $createInput) {
      code
      message
      success
      webhook {
        urn
      }
    }
  }
`, {
  createInput: {
    description: 'Brand updates',
    enabled: true,
    events: ['brand.updated'],
    url: webhookEndpointUrl
  }
})

Retrieve a Brand and Subscribe

Fetch the brand data and use its URN to subscribe to updates.
// 1. Get the brand
const brand = await BrandApi('google.com')

// 2. Subscribe to updates for this specific brand
await graphql(`
  mutation AddWebhookSubscriptions($webhookUrn: URN!, $subscriptions: [URN!]!) {
    addWebhookSubscriptions(webhook: $webhookUrn, subscriptions: $subscriptions) {
      code
      message
      success
    }
  }
`, {
  webhookUrn: webhook.urn,
  subscriptions: [brand.urn]
})

Unsubscribe

If you no longer need updates for a brand, use the removeWebhookSubscriptions mutation.
await graphql(`
  mutation RemoveWebhookSubscriptions($webhookUrn: URN!, $subscriptions: [URN!]!) {
    removeWebhookSubscriptions(webhook: $webhookUrn, subscriptions: $subscriptions) {
      code
      message
      success
    }
  }
`, {
  webhookUrn: webhook.urn,
  subscriptions: [brand.urn]
})