HubSpot / hubspot-api-php

HubSpot API PHP Client Libraries for V3 version of the API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Association subscription types missing from Webhooks SubscriptionCreateRequest

ryross opened this issue · comments

When trying to create a webhook for association subscriptions with this code:

use HubSpot\Client\Webhooks\Model\SubscriptionCreateRequest;
use HubSpot\Client\Webhooks\ApiException;

        $subscriptionCreateRequest = new SubscriptionCreateRequest([
            'event_type' => 'deal.associationChange',
            'active' => true,
        ]);

        try {
            $apiResponse = $client->webhooks()->subscriptionsApi()->create($appId, $subscriptionCreateRequest);
            dump($apiResponse);
        } catch (ApiException $e) {
            echo "Exception when calling subscriptions_api->create: ", $e->getMessage();

        }

I get this error:

Invalid value 'deal.associationChange' for 'event_type', must be one of 'contact.propertyChange', 'company.propertyChange', 'deal.propertyChange', 'ticket.propertyChange', 'product.propertyChange', 'line_item.propertyChange', 'contact.creation', 'contact.deletion', 'contact.privacyDeletion', 'company.creation', 'company.deletion', 'deal.creation', 'deal.deletion', 'ticket.creation', 'ticket.deletion', 'product.creation', 'product.deletion', 'line_item.creation', 'line_item.deletion', 'conversation.creation', 'conversation.deletion', 'conversation.newMessage', 'conversation.privacyDeletion', 'conversation.propertyChange'

The association change event types are missing from SubscriptionCreateRequest:

    public const EVENT_TYPE_CONTACT_PROPERTY_CHANGE = 'contact.propertyChange';
    public const EVENT_TYPE_COMPANY_PROPERTY_CHANGE = 'company.propertyChange';
    public const EVENT_TYPE_DEAL_PROPERTY_CHANGE = 'deal.propertyChange';
    public const EVENT_TYPE_TICKET_PROPERTY_CHANGE = 'ticket.propertyChange';
    public const EVENT_TYPE_PRODUCT_PROPERTY_CHANGE = 'product.propertyChange';
    public const EVENT_TYPE_LINE_ITEM_PROPERTY_CHANGE = 'line_item.propertyChange';
    public const EVENT_TYPE_CONTACT_CREATION = 'contact.creation';
    public const EVENT_TYPE_CONTACT_DELETION = 'contact.deletion';
    public const EVENT_TYPE_CONTACT_PRIVACY_DELETION = 'contact.privacyDeletion';
    public const EVENT_TYPE_COMPANY_CREATION = 'company.creation';
    public const EVENT_TYPE_COMPANY_DELETION = 'company.deletion';
    public const EVENT_TYPE_DEAL_CREATION = 'deal.creation';
    public const EVENT_TYPE_DEAL_DELETION = 'deal.deletion';
    public const EVENT_TYPE_TICKET_CREATION = 'ticket.creation';
    public const EVENT_TYPE_TICKET_DELETION = 'ticket.deletion';
    public const EVENT_TYPE_PRODUCT_CREATION = 'product.creation';
    public const EVENT_TYPE_PRODUCT_DELETION = 'product.deletion';
    public const EVENT_TYPE_LINE_ITEM_CREATION = 'line_item.creation';
    public const EVENT_TYPE_LINE_ITEM_DELETION = 'line_item.deletion';
    public const EVENT_TYPE_CONVERSATION_CREATION = 'conversation.creation';
    public const EVENT_TYPE_CONVERSATION_DELETION = 'conversation.deletion';
    public const EVENT_TYPE_CONVERSATION_NEW_MESSAGE = 'conversation.newMessage';
    public const EVENT_TYPE_CONVERSATION_PRIVACY_DELETION = 'conversation.privacyDeletion';
    public const EVENT_TYPE_CONVERSATION_PROPERTY_CHANGE = 'conversation.propertyChange';

This is what I ended up getting to work, after forking and making #237

        $response = $client->apiRequest([
            'method' => 'POST',
            'path' => "/webhooks/v3/{$appId}/subscriptions",
            'body' => [
                'eventType' => 'deal.associationChange',
                'active' => true
            ],
        ]);

Now that I've made the subscription, $webhooks = $client->webhooks()->subscriptionsApi()->getAll($appId); won't work and produces the same error because it can't deserialize.

Is the script to generate the library from the openapi spec open source?

@ksvirkou-hubspot Who can we ask to update https://api.hubspot.com/api-catalog-public/v1/apis/webhooks/v3 so that it includes the association subscription types?

commented

I'll ask.