Extracting Data From The URL
When To Use
Imagine you have an app that has an integration with a tool like Zapier. If you want to add a button that pings Zapier with the record ID so that one of the steps in Zapier uses the app's own integration to get the record and so something with it, very often, you'll find exactly what you need right in the URL of the record you're on.
For Example
Let's take a look at the URL of a record in Copper, a popular CRM -
https://app.copper.com/companies/1234567890/app/#/contact/9876543210
In this example, the 1234567890
is your company ID and the 9876543210
is the ID of the contact you're on - and that's exactly what you need in any sort of Zap. Once you see URLs like this a couple of times, you'll start to recognize the important bits of a URL.
Using In A Button
Set up your button to call your webhook and pass the {tab_url_encoded}
variable to it. It's important to use the encoded version of this variable since you're passing a URL inside a URL.
https://hooks.zapier.com/hooks/catch/12345678/b9ix4gg?url={tab_url_encoded}
Now your Zap will have access to the URL you were on and can extract the important bits to use in subsequent actions.
Extracting
Depending on the tool you use (Zapier, etc), there are different ways to extract the bits you need out of a URL. Zapier, for example, has a couple of parsing tools. Take a look at this common workflow when using an action like above.
The steps are
- Trigger the Zap with our URL in the querystring
- Decode the URL using the Zapier Decode URL task.
- Extract the contact's ID from the URL we passed to Zapier
- Use the ID to look up the contact in Copper or any other CRM or app.
- Do anything else you need.
Step 3 is the important one and you can do it several different ways:
- Split the URL by slashes and grab the last part
- If your URL only has one numeric bit, you can try to Extract Number
- Or use Regular Expressions (see below)
For Advanced Users - Regular Expressions
The most powerful way to extract bits from URLs is Regular Expressions. Almost any worklfow tool you use will have an option to use them. For the example above, the regular expression we used is
(\d+)\/?$
Remember that we are always happy to help if you run into problems. Please reach out!