Skip to content

integrationWebhookCreate

Subscribe to webhook events from an integration app context. Creates a new webhook registration that will receive HTTP POST notifications when the specified event type occurs.

Required scope: edit_integrations


Mutation

graphql
mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) {
  integrationWebhookCreate(input: $input) {
    id
    type
    health
    endPoint
  }
}

Input — IntegrationWebhookInput

FieldTypeRequiredDescription
endPointStringHTTPS URL that will receive webhook POST requests
typeStringEvent type to subscribe to (e.g. "order/created")
headersJSONCustom HTTP headers to include in every webhook delivery

The endPoint must use HTTPS. HTTP endpoints are rejected. The headers field accepts a JSON object — useful for adding authentication headers to your endpoint.


Example Variables

json
{
  "input": {
    "endPoint": "https://my-app.example.com/hooks/orders",
    "type": "order/created",
    "headers": {
      "X-Secret-Token": "my-internal-token"
    }
  }
}

Example Response

json
{
  "data": {
    "integrationWebhookCreate": {
      "id": "wh_550e8400-e29b-41d4-a716-446655440000",
      "type": "order/created",
      "health": "HEALTHY",
      "endPoint": "https://my-app.example.com/hooks/orders"
    }
  }
}

Code Examples

bash
curl -X POST https://api-v3.happycolis.com/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "query": "mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) { integrationWebhookCreate(input: $input) { id type health endPoint } }",
    "variables": {
      "input": {
        "endPoint": "https://my-app.example.com/hooks/orders",
        "type": "order/created",
        "headers": { "X-Secret-Token": "my-internal-token" }
      }
    }
  }'
js
async function createIntegrationWebhook(accessToken, input) {
  const response = await fetch('https://api-v3.happycolis.com/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${accessToken}`,
    },
    body: JSON.stringify({
      query: `
        mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) {
          integrationWebhookCreate(input: $input) {
            id
            type
            health
            endPoint
          }
        }
      `,
      variables: { input },
    }),
  });

  const { data, errors } = await response.json();
  if (errors) throw new Error(errors[0].message);
  return data.integrationWebhookCreate;
}

const webhook = await createIntegrationWebhook(process.env.ACCESS_TOKEN, {
  endPoint: 'https://my-app.example.com/hooks/orders',
  type: 'order/created',
  headers: { 'X-Secret-Token': 'my-internal-token' },
});

console.log(`Webhook registered: ${webhook.id}`);
python
import os
import requests

def create_integration_webhook(access_token: str, input_data: dict) -> dict:
    mutation = """
    mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) {
      integrationWebhookCreate(input: $input) {
        id
        type
        health
        endPoint
      }
    }
    """
    response = requests.post(
        'https://api-v3.happycolis.com/graphql',
        headers={
            'Authorization': f'Bearer {access_token}',
            'Content-Type': 'application/json',
        },
        json={'query': mutation, 'variables': {'input': input_data}},
    )
    result = response.json()
    if 'errors' in result:
        raise Exception(result['errors'][0]['message'])
    return result['data']['integrationWebhookCreate']

webhook = create_integration_webhook(os.environ['ACCESS_TOKEN'], {
    'endPoint': 'https://my-app.example.com/hooks/orders',
    'type': 'order/created',
    'headers': {'X-Secret-Token': 'my-internal-token'},
})
print(f"Webhook registered: {webhook['id']}")
php
<?php
$mutation = <<<'GQL'
mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) {
  integrationWebhookCreate(input: $input) {
    id
    type
    health
    endPoint
  }
}
GQL;

$payload = json_encode([
    'query'     => $mutation,
    'variables' => [
        'input' => [
            'endPoint' => 'https://my-app.example.com/hooks/orders',
            'type'     => 'order/created',
            'headers'  => ['X-Secret-Token' => 'my-internal-token'],
        ],
    ],
]);

$ch = curl_init('https://api-v3.happycolis.com/graphql');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => $payload,
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . getenv('ACCESS_TOKEN'),
    ],
]);

$result = json_decode(curl_exec($ch), true);
curl_close($ch);

echo 'Webhook registered: ' . $result['data']['integrationWebhookCreate']['id'];
go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func createIntegrationWebhook(accessToken string, input map[string]any) (map[string]any, error) {
	mutation := `
		mutation IntegrationWebhookCreate($input: IntegrationWebhookInput!) {
			integrationWebhookCreate(input: $input) {
				id
				type
				health
				endPoint
			}
		}`

	body, _ := json.Marshal(map[string]any{
		"query":     mutation,
		"variables": map[string]any{"input": input},
	})

	req, _ := http.NewRequest("POST", "https://api-v3.happycolis.com/graphql", bytes.NewBuffer(body))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer "+accessToken)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	var result map[string]any
	json.NewDecoder(resp.Body).Decode(&result)

	if errs, ok := result["errors"]; ok {
		return nil, fmt.Errorf("graphql error: %v", errs)
	}
	data := result["data"].(map[string]any)
	return data["integrationWebhookCreate"].(map[string]any), nil
}

func main() {
	webhook, err := createIntegrationWebhook(os.Getenv("ACCESS_TOKEN"), map[string]any{
		"endPoint": "https://my-app.example.com/hooks/orders",
		"type":     "order/created",
		"headers":  map[string]any{"X-Secret-Token": "my-internal-token"},
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("Webhook registered: %s\n", webhook["id"])
}

HappyColis API Documentation