Identify campaign related to form

We have a set up where a couple workflows in a campaign that need to reference a value stored as a campaign property (it’s a record ID for an external system). This is a repeating pattern so we’re trying to genericize it as much as possible (i.e. not just manually copy the campaign property into every workflow)… I’ve managed to accomplish this with the following sequence of steps:

When any form is submitted:

  1. Retrieve all campaigns, sorted by most recent:

https://api.hubapi.com/marketing/v3/campaigns/?_sort=updatedAt&properties=hs_name,custom_campaign_value

  1. Iterate through each by guid and retrieve all forms

https://api.hubapi.com/marketing/v3/campaigns/campaign-guid-value/assets/FORM

  1. If the contact’s “recent_conversion_event_name” property matches the form name, we know the “custom_campaign_value” for that campaign is the right one

…however this feels pretty inefficient. So! Question:

Is there any way to:

  1. Look up a form by it’s name (i.e. find the form represented in “recent_conversion_event_name”)
  2. Identify the campaign guid that form is tied to as an asset

Thanks!

Hi @Canadero, I hope that you are well!
Great question, thanks for asking the HubSpot Community!
I’d like to share some resources that might be might help you:
- Manage asset associations
- Add asset association
- Find your form GUID
Also, I’d love to put you in touch with some of our Top Experts: Hi @LMeert, @sylvain_tirreau and @zach_threadint do you have suggestions to help @Canadero, please?
Have a great day and thanks so much in advance for your help! :star:
Bérangère

Hi,

There’s no straightforward way to do what you want. However, you can optimize your approach.

You can use the endpoint https://api.hubapi.com/marketing/v3/campaigns/batch/read. The response groups the assets (including forms) for each campaign, and you just have to search for your formGUID to extract the campaignGUID.

If the pages that contain your forms are hosted by Hubspot, you can also add a hidden field to your forms in which you put the campaign ID linked to the form in question.

Best