-1

Ive built an APi that receives the name of a person and returns some information about that person.

I want to make it easy for third parties to use my API in their website, so I decided to create a JS widget that can be added as a script tag.

The widget is essentially a modal that accepts form data and has a submit button to POST the data to my API.

My problem is, how can I make a third parties backend server receive the response of the API. My understanding is that if called from client side JS, the response will be delivered to the users browser session rather than the third parties backend server.

Do i need to make my API do a post call to the third party server? (i would need to make a configuration for every third party who uses my API then) or can i write javascript in my widget that will do this post to their server? Or is my novice understanding of JS completely wrong here?

Tom D
  • 1
  • 3
  • Please post your code otherwise we cannot help. – Worm Dec 19 '18 at 23:36
  • The third party would need to make their server make the request to your api endpoint. Or as part of the form you can ask for a postback url which your backend could then use to send a post request to that. – Patrick Evans Dec 19 '18 at 23:45

1 Answers1

0

What you're looking for is referred to as callback url.

Essentially the user needs to add a callback url (pointing to their backend endpoint) which will handle data sent by your server. Your widget should accept a callback URL whether in the constructor or upon submit.

Your server upon getting the request needs to send the data to the callback url.

POST /api.example.com/foo?callbackURL=http://my.server.com/bar
kemicofa ghost
  • 14,587
  • 5
  • 63
  • 112