When Zapier doesnât have the integrations or features that youâre looking for, you donât need to give up on building the automation.
Instead, you can just use an API call to create the functionality yourself.Â
In this post, weâll show you how to write an API call in Zapier.Â
Weâll walk you through some strategies you can use to write API calls in your Zaps, even if youâre not familiar with coding.Â
You can use these techniques for both the âWebhooks by Zapierâ action, or Zapierâs new âAPI Requestâ actions, which are currently in beta.Â
When and Why to Use an API Call
First, letâs explore when and why you should use API requests or webhooks in Zapier.Â
In most cases, youâll want to use an API call whenever Zapier doesnât natively support the functionality that you want to access.Â
There are three main use cases for writing API calls in your Zaps:
⢠If Zapier doesnât have an integration for the app you want to automate, you may be able to build your Zap with webhooks instead.Â
⢠If Zapier does support the app you want to automate, but doesnât support the specific action you want to perform, then you can try to add that action with a webhook action, to make a custom API call.Â
⢠Finally, if Zapier supports your app and your desired action, but doesnât have all of the configuration settings that you want to use, then webhooks with an API request may be able to help.Â
Discover what you can automate with XRay.Tools
Since using webhooks in Zapier is mostly about compensating for the things Zapier canât do, weâd always recommend doing a quick search on XRay.Tools before you commit to writing an API call.Â
Just enter the name of your app, and youâll see every trigger, action, and search that you can automate with it in Zapier, Make and Workato.Â
Even if youâre pretty sure Zapier doesnât support what you want to do, itâs always worth a quick check first. Zapier updates support for their apps weekly, so you never know what may have changed since you last tried building your workflow.Â
Zapierâs new âAPI Requestsâ actions
Checking XRay.Tools will also show you if your app has support for Zapierâs new âAPI Requestsâ feature.Â
API requests are in beta at time of writing. Right now, they offer somewhat similar functionality to the âWebhooks by Zapierâ action which weâll be using first in this tutorial, but they let you skip a few steps by including authorization, which is often one of the trickiest parts of API Calls.Â
On the other hand, you will need to write the body of your request as code, and wonât be able to structure it as a simple form, so it may be easier for low-coders to stick with the âWebhooks by Zapierâ action.Â
If your app has support for API Requests, youâll see the action right alongside all the appâs other available actions in XRay.Tools.Â
If you donât see an âAPI Requestâ action, or if you just donât want to write out your request with code, then you can just use the âWebhooks by Zapierâ action instead.Â
Writing an API Call with âWebhooks by Zapierâ
Now letâs go through the process of creating an API call in Zapier step by step.Â
Before we start building an API call, weâll first take a moment to confirm that we canât do what we want with Zapierâs prebuilt actions.Â
For our example, we want to automatically create projects in Harvest. This is something we can do in Zapier.
However, we also want to make sure that every project created by this automation is set to a fixed fee of $750.
âFixed feeâ isnât an option that Zapier gives us, so weâll need to go with an API call instead. And since âAPI requestâ isnât available for Zapierâs Harvest integration, weâll need to use the dedicated âWebhooks by Zapierâ integration.Â
Our example Zap already has a trigger to watch for new records in Airtable, so weâll add an action by searching for âWebhooks by Zapierâ.Â
The webhooks action will prompt you to pick an event type. If youâre not familiar with writing code, or API calls specifically, this might already seem a little confusing, but donât worry; thereâs an easy way to make sense of it.Â
Your options are Custom Request, GET, POST, and PUT.Â
⢠GET will let you search for existing data in your app.Â
⢠POST will allow you to create new data.
⢠PUT will allow you to create new data, or update existing data.Â
⢠Custom Request will let you choose other methods, like PATCH or DELETE.Â
â
NOTE: Zapier does not natively support any DELETE actions across any application, so Custom Requests will be your only option if youâre trying to automatically delete something. If you choose to write an API call to delete data, be very careful; any errors in your API call might end up deleting data you didnât intend to destroy.Â
â
You can probably figure out which will suit your needs just based on those descriptions, but this is as good a time as any to check your appâs API docs to be sure. Youâll be referencing the API docs a lot as youâre building, so you may as well start early.
If you Google â[your app] api docsâ, the official API documentation should be one of the first results.Â
Harvestâs API docs are very well organized, and include lots of useful examples to help us get started.Â
Unfortunately, not every app will keep neat and tidy documentation like this, but if youâre struggling, you can always search for support from other users or leave a comment below and weâll try to help you out.Â
Since we want to create a project in our example, weâll scroll down to the âProjects APIâ section, and click on âProjectsâ.Â
Here, the docs explain all of the attributes that make up a âprojectâ object in the app. These are all the settings that we have access to via Harvestâs API. If it isnât listed here, then we canât add it, update it, find it, or delete it.Â
Under âCreate a projectâ, weâll see more specific information about actually creating a project. Right at the top of the section, we can see the type of request weâll need to use: POST.Â
So weâll choose POST as our event back in our Zap, then continue.Â
Building and configuring a basic API call in Zapier
Start with the bare minimum
When youâre creating an API call in Zapier, the best approach is to start with the bare minimum, and build up from there.Â
Your first goal should be to successfully create an object with the webhooks step. Just provide the required fields, and type in static data for now.Â
Once youâve done that, you can go back and configure more specific settings, or add dynamic data from earlier steps in your Zap.Â
URL and payload typeÂ
Every API call needs a URL to send your request to. Your appâs API docs will specify the required URL for your desired action.Â
In the Harvest API docs we can see an example of a full API call that will create a new project.
In the first line, after âcurlâ, we can see the URL we need to use. Once youâve found your URL, just copy and paste it into Zapier, without the quotes.Â
If youâre primarily a no-code builder, weâd recommend sticking with âformâ for the payload type.Â
That will let you enter all the data you need into each form field, similar to any other step in Zapier, instead of needing to mess around with specific coding syntax.Â
If youâre more comfortable with coding, you can choose another option like âjsonâ or ârawâ, but weâll stick with âformâ for our example.
Technically, these three formats are equivalent, so it's up to you and what youâre comfortable with.Â
Filling in the data fields
Under this data section, youâll need to fill in information for each attribute of the object you want to create (or update, or find).Â
In our case, that means weâll need to define several attributes to create our âprojectâ object.Â
Going back to Harvestâs API docs, we can see that several parameters are bolded. These are the parameters that are listed as ârequiredâ, so these are the ones weâll start with.Â
Again, itâs always best to start with only the required fields. Even though the optional parameters include settings that we want to access, we can add those once we know that our API call is working as intended.Â
Once youâve determined which fields are required, create a key-value pair for each of them in your Zap.
In our example, weâve added key-value pairs for client_id, name, is_billable, bill_by, and budget_by. These labels are the âkeysâ - essentially, the name of each pair. Next, weâll fill in the âvaluesâ - the setting or content it includes.Â
The client ID attribute will tell Harvest which client we want to create the project for. Weâll grab the ID from the URL bar of the clientâs page in our Harvest account, and paste it into Zapier.
This is a common trick for finding IDs for objects in your apps. Logging into your SaaS tool will often show your objectâs ID inside of the URL bar - whether that object is a client in Harvest, a page in Notion, or a task in Trello.Â
Next, we need a name for our project. The API docs indicate that this parameter accepts a âstringâ, which basically means that it just needs text.
We can give our Project any name we want. Weâll enter it without any quotes or other special characters.Â
âIs_billableâ is a boolean parameter, which means it accepts values of âtrueâ or âfalseâ. Since we want our project to be billable, weâll enter âtrueâ. Again, weâre not including any quotes or any other special characters.Â
âBill_by also accepts a string, but in this case, the string has to match one of the four options indicated in the description. Weâll bill by âprojectâ, and enter Project exactly as it appears in the documentation.Â
Budget_by is similar to bill_by. Weâll enter âpersonâ to set our budget based on hours per person.Â
The remaining options can be left to their defaults for our API call. In most cases, you wonât need to edit these.Â
Adding headers for authentication and more
All of the data we want to create is in place, but we need to fill out the headers first. Headers are often used in API calls to identify and authenticate the user making the request.Â
Just as a reminder: if youâre using an âAPI Requestâ action instead of a webhook, you wonât need to include any additional headers for authorization.
If we go back to the example API call that we found in the Harvest docs, we can see three lines of code flagged with an âHâ. These are the headers that we need to include in our API call.Â
Weâll add each of them as keys under Headers, leaving out the colon and quotes: Authorization, Harvest-Account-Id, and User-Agent.
For the value associated with âAuthorizationâ, we need to enter the term âBearerâ and a space, then provide a personal access token from Harvest.Â
We can just go to the developers section in Harvest to create a token and copy it. We can also see our Account ID in this same section, which weâll need next.Â
Sensitive data like access tokens and account IDs can generally be found under a âdevelopersâ setting, or elsewhere in your appâs preferences. Your API docs may contain information specific to your app, or you may need to search through their other support docs.Â
Once weâve pasted both of these into Zapier, we just need to provide a User Agent. This simply identifies the user making the API call. Their API docs donât appear to include any specific information about whatâs required here.Â
Harvest suggests using your email address, but it appears that you can put anything in this field; the API call will work anyway.Â
This is an area of API calls that will differ for every application. The requirements in your header can be tricky, so be patient and test one thing at a time.Â
Now that we have our data and headers all set, we can test the step.Â
Success! Weâve created a project. If we check Harvest, we can see the project, complete with all of the options we configured.Â
Adding optional parameters and dynamic data
Now that weâve built our bare minimum API call, we can go back and add the optional parameters we want to use, and dynamic data generated by Zapier.Â
Building up from a simple API call and testing your changes one step at a time will be a huge help when you inevitably run into some errors.
It will make it much easier to isolate the change thatâs likely to have caused the error in the first place.Â
First, weâll go back to the data section of our API call and add key-value pairs for âis_fixed_feeâ, which weâll set to âtrueâ, and âfeeâ, which weâll set to 750.Â
Then, weâll add some dynamic data to one of the other data fields. Weâll replace the project name with the âNameâ field that Zapier retrieved from Airtable.Â
Weâll test the Zap again, and confirm that a project was created in Harvest with a fixed fee of $750.Â
Writing an API call with Zapierâs new âAPI Requestsâ actions
Next, weâll take a quick look at the other method of creating API calls in Zapier.
As mentioned earlier, the API request action is only available for a select list of apps right now. You can check the whole list in this Zapier support page, or you can search for your app in XRay.Tools to see if âAPI requestâ is supported.Â
For our example, weâll use the API request action to send a message in Slack, since we can see here in XRay.Tools that Slack has an âAPI requestâ action available.Â
Weâll pull up Slackâs API docs for reference, and create a new Slack action. Weâll choose âAPI requestâ.Â
The API Request options are somewhat similar to our earlier Webhooks steps, but there are some key differences.Â
As Zapier notes, authentication is handled automatically, so we donât need to include any headers for authentication.Â
You can also only pass along raw data with the API requests action; you currently canât enter key-value pairs into convenient text fields like before.Â
But just as before, youâll need to provide a Method and a URL, which you can find in your appâs API docs.Â
By default, this action will send URL-encoded data. URL encoding is a bit of a pain to work with, so in our example, weâll add a header to change the Content type to application/JSON.Â
That will make our body much easier to read, and we wonât have to include characters like â%20â for every space.Â
Like most API docs, Slackâs includes full examples of API calls. Weâll just copy and paste an example of a simple Slack message into the body of our API call, and update it with our own channel ID and text.Â
â
NOTE: make sure that your code syntax matches the content type specified in your header. Since weâve set the content type to JSON, our body must be formatted as a JSON object.Â
With our API call configured, weâll test the step. Note that when you use the API Request action, your Zapier test may be considered âsuccessfulâ even if your API request failed.Â
If you were able to send a request and get a response, Zapier usually considers that to be a success, even if it returns an error.Â
So make sure to review the output of the step, and check your tool directly, before continuing.Â
When we check Slack, we can see the message sent exactly as we set it up.Â
â
All in all, weâd recommend that most low-coders stick with Webhooks by Zapier for now. API Requests still have a lot of bugs to work out, and theyâll require you to write out the entire body of the request.
If youâre struggling to get authentication to work in a Webhooks step, then you can try out API requests. Otherwise, I think Webhooks is the way to go, especially since ârequestsâ are still in beta and limited to a few dozen tools.
â
Understanding and troubleshooting error messages
Before we wrap up this walkthrough, letâs quickly go over the kinds of error messages youâre likely to see as youâre building API calls in Zapier. Â
If you get an error when you test your âWebhooks by Zapierâ or âAPI Requestsâ action, youâll likely see either a 400 response, or a 500 response.Â
400 Errors
If you see a 400 error, like 404, that means thereâs an error in your configuration. Check your API docs again and make sure youâve configured everything correctly.Â
Look for misplaced commas, or extra quotes, or any other small typo in your syntax that might have broken your API call.
If you still keep getting a 400 error, try searching on a resource like Stack Overflow for the issue to get more information.Â
Again, keeping your API call simple to start with will make it much easier to find the problem. There will be far fewer variables that you need to test and control for.Â
500 Errors
If you see a 500 message, like 503, then thereâs an error in the app itself. Wait a moment and try again to see if the issue resolves itself.Â
If you keep getting a 500 error, check to see if the appâs servers are down at a site like downdetector.com. Â
You may have to wait a while for the appâs dev team to address the issue, but thereâs nothing that you can do to fix it. If the tool is down, the tool is down. Youâll just have to wait.Â
Ultimately, building API calls will often require a lot of trial and error as you figure out whatâs working and what isnât.Â
Just take your time, read the docs carefully, and look for help when you need it, the comments section below is a great place to start. There are also thousands of people on Zapierâs forums, StackOverflow, and other communities building similar things who can give you great advice.Â
Create any automation you want with API calls
Tools like Zapier provide thousands of integrations for popular apps, but sometimes, the solution you need wonât be available right out of the box.Â
Even if you consider yourself a no-code builder, making the jump to a little low-code with API calls and webhooks will unlock a ton of new possibilities.Â
So when you want to create an integration that Zapier doesnât have, donât be afraid to open up the API docs and start reading.Â
If youâd like to learn more about no-code and low-code automations with tools like Zapier and Make, be sure to check out our blog or our YouTube channel. You can also follow XRay on Twitter, Facebook, or LinkedIn.
â