Sometimes, you need to pass extra context data to the integration setup. For example, if a user is setting an integration inside a particular campaign in your app, you want campaign_id to be passed to the integration. You can pass any data to the SDK via the extra parameter under xIntegryConfig.appAuth.extras
Example Scenario
Let's say your app has customer accounts; each account can have many campaigns, and each campaign sends out emails to subscribers inside that campaign. You want your users to create integrations from inside the campaign where new customers added to, say, HubSpot are added to the campaign.
In flow-speak: whenever there's a new contact added to Hubspot, start this campaign in this account for that contact. More specifically, make an HTTP call to my API adding that contact to this campaign.
This means Integry needs to pass the account ID and the campaign ID to you in the "Start a campaign" HTTP call.
However, in order for Integry to pass those ID values, you have to first pass them to Integry's SDK when the integration is setup You can then consume them in the HTTP call body so they get passed back.
Note: Integry makes secure calls to your API endpoint by passing an API key in the header or parameters. The API key can be user-specific or Integry-specific.
In this example, if the integrations were at the user-level, i.e., one integration per CRM per user, and your app had user-specific API keys, you could simply use that to ID the user. However, the integrations are at the campaign-level, i.e., one integration per campaign per CRM per user, so the API key alone cannot be used. In fact, lets assume that the API key is Integry-specific so it can't be used to ID the account anyway.
Let us begin with the second part: consuming the values in the HTTP call body.
Consume the values in the HTTP call
- First, let's create the flow by adding a Trigger Contact Created from HubSpot, followed by a Make HTTP Call step under it as we saw above:
- Click HTTP call to edit it, set the method to POST and add a your API's URL. In this example, we will use a URL from webhook.site to demonstrate. Toggle to the Body tab.
- Specify the body payload.
-
{ "email":"{steps.hubspot_contact_created.out.email}", "account_id":"", "campaign_id":"" }
- The email field was mapped using the output of the trigger step.
-
- Place your cursor between the "" value for the
account_id
field, and click +. - Click Authorization.
- Click the > next to "authorization" to expand it.
- Click the > next to "token" to expand it.
- Click the > next to "extras" to expand it.
- Click "business_unit_id" to add the field. Don't worry, you'll get to rename it.
- As you can see,
business_unit_id
is a field in theextras
object. You can rename that to whatever field name makes sense in your case. - The best part: just like that field, you can pass any number of fields in that array. You won't see them in the + menu under extras but as long as you pass them at setup time (next section), we'll pass them back.
That's it for the HTTP call. Save the flow and close it. Now, let's head over to the embed code so we can pass those values.
Pass the value in the embed code
Here's the standard embed code. You can generate it via the embed button in your account.
<script> // Wait for the DOM (web page content) to be fully loaded window.addEventListener("DOMContentLoaded", async function(){ // Replace '<app_key>', '<hash>', and '<user_id>' with your actual values const integryHandler = new IntegryJS({ appKey, hash, userId, xIntegryConfig: { appAuth: { apiKey: "", /* Add your App API key here. It will be use to authenticate user */ } }, options: { title: "Apps", /* Add title here E.g. "Apps" */ tags: [], /* Which Apps do you want to show? Pass tag names in array E.g. ["Production","Beta"] */ // All objects, that can be used, are passed in, as shown below objects: { "Contact": { "firstName": "John", "lastName": "Doe", "email": "johndoe@example.com", "dateOfBirth": "1990-01-01", "gender": "male", "age": 20 "phone": "555-555-1234", "address": { "postalCode": "10001", "city": "New York", "state": "NY", "street": "123 Main St", "country": "USA" }, }, }, }, }); }); </script>
We'll be working in the appAuth
array in xIntegryConfig
.
- Add an array called
extras
with the additional fields.-
appAuth: { apiKey: "trial-key", extras: { "accountID":"ABC", "campaignID":"123" } }
-
- Pass the
apiKey
,accountID
andcampaignID
from your app as the values of those fields. You can use the hardcoded values to try.
You're done!
Simply refresh the page containing the embed code, then using the Integry widget, set up a new integration of a flow that consumes the extra values, and you should receive them in the payload of the HTTP call from Integry.
Here, we created a contact in Hubspot and received this on the webhook:
The email field came from the trigger, while the other two fields are the extra values you passed at setup time.
Note: If you used Hubspot to try this, you may have to wait a bit. Hubspot doesn't support event-based webhooks, so, instead, we poll them every 5 minutes for new data. Want faster results? Use Mailchimp.
Comments
0 comments
Please sign in to leave a comment.