-1

I'm new to ampscript, I would like to expose a restful service which will respond with json body. I have tried multiple sites and everywhere finding answered to hit an endpoint and read response, but not able to find ways to create and expose a restful service.

user3172208
  • 91
  • 1
  • 5

1 Answers1

0

The following code will make an HTTPGet request with a header and set the response as an AMPscript variable:

<script runat="server">

Platform.Load("Core","1");

var url = "https://httpbin.org/anything";
var headerNames = ["Accept"];
var headerValues = ["application/json"];
var response = HTTP.Get(url, headerNames, headerValues);
Variable.SetValue("response",response.Content);

</script>

Response: %%=v(@response)=%%

did I understand true?

Mahmonir Bakhtiyari
  • 546
  • 1
  • 8
  • 21
  • Hi, Thanks for your response ..The code you have provided is to consume a HTTP service provided by a third person. But my requirement is to create an HTTP endpoint using ampscript so that a third person should be able to consume it. – user3172208 Dec 19 '18 at 04:50