Skip to main content
Best answer

How to use different API endpoints for each user?


How would I use a different endpoint for each integration user? I have a slightly different endpoint for each client and would like them to enter the URL (or part of the URL) as part of zap setup.

 

Bruce

Best answer by ikbelkirasanBest answer by ikbelkirasan

@brucewheaton Sounds like you made some progress! You just need to fix the url in the request, it should be bundle.authData.api_url instead of bundle.auth.api_url.

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

9 replies

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • August 18, 2021

@brucewheaton - Add a field for the API URL in the authentication, let’s call it api_url. You can reference it later from {{bundle.authData.api_url}}.


  • Author
  • Beginner
  • 4 replies
  • August 18, 2021

Thanks!

As an environment variable? 

ThenI can reference that environment variable in the URL field?


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • August 18, 2021

@brucewheaton You’re welcome!

As an environment variable, it will be the same for all the users. You’ll need to add it as an authentication field instead so that each connection has its own API URL.


  • Author
  • Beginner
  • 4 replies
  • August 18, 2021

That makes sense - I don’t see where to add that though, do I need to switch to ‘Code Mode’? There’s a ‘Connection Label’ item on that page but no variables to edit/add.


Forum|alt.badge.img+9
  • Zapier Staff
  • 331 replies
  • August 18, 2021

 

Add an authentication field, which will prompt the user as they are configuring their credentials for your app.  

 

You can define an input mask as well to help your users understand what part of the URL you’re expecting them to enter. 

 

 


  • Author
  • Beginner
  • 4 replies
  • August 18, 2021

Ah, that could be why I don’t see it - I’m using Basic Auth for this (as a sort of API key).

Is there still a way to do it?

 


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • August 18, 2021

@brucewheaton - In that case, you’ll need to switch to API Key authentication scheme and add the Basic authentication fields manually then in your triggers and actions, you should switch to the code mode.

If you name the Basic authentication fields username & password then the Authorization header should be assigned this value: "Basic " + Buffer.from(bundle.authData.username + ":" + bundle.authData.password).toString("base64")


  • Author
  • Beginner
  • 4 replies
  • August 18, 2021

Thanks again!

 

EDIT - damn. Somehow bundle.auth.api_url got inserted there, not bundle.authData.api_url.

 

Works great now!

 

That makes sense, and I edited the auth and test sections, got a good test, but when I try to test the API I get:

TypeError: Cannot read property 'api_url' of undefined at eval (eval at makeFunction (/var/task/node_modules/zapier-platform-core/src/tools/schema-tools.js:11:39), <anonymous>:4:20)

The code looks like this:

const options = {
  url: bundle.auth.api_url,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': "Basic " + Buffer.from(bundle.authData.username + ":" + bundle.authData.password).toString("base64"),
    'X-VEVOMO-ATTENDEE-TYPE': bundle.inputData.vevomo_attendee_type
  },

and I set a new ‘account’ to be sure that the URL was in there (same values that worked for the test).

 

Feels like it’s close but the auth isn’t there? The same code works in the test area.

 


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • August 18, 2021

@brucewheaton Sounds like you made some progress! You just need to fix the url in the request, it should be bundle.authData.api_url instead of bundle.auth.api_url.