0

I'm trying to figure out how to connect my signup to sender.net API so when someone fills out the form it will be added to my subscriber list. Sender.net provided me with this information to help:

  1. API is implemented through HTTP protocool, using POST. Responses are returned in .

  2. All API requested shall be directed at http://app.sneder.net/api/api.

  3. Request data must be encoded in , in POST parameter named data.

I wrote this code but nothing appears on my subscriber list, please see below:

<!DOCTYPE html>
<html>

<head>
  <title>test with sender</title>
</head>

<body>

  <h1>This is to test sender.net API "POST" </h1>

  <form>
    <input type="text" name="Fname" placeholder="first name">
    <input type="text" name="Lname" placeholder="last name">
    <input type="email" name="Email" placeholder="email address">
    <button type="submit" onclick="JSONTest()"> Let the Post req begin! 
            </button>
  </form>

  <script type="text/javascript">
    JSONTest = function() {
      $.ajax({
        url: "https://app.sender.net/api/",
        method: "POST",
        datatype: "JSON",
        data: {
          method: "listSubscribe",
          params: {
            api_key: "my key number",
            list_id: "my id number",
            emails: ["Email", "Fname", "Lname"],
            update_existing: true
          }
        }
      });
    };
  </script>

  <!-- Jquery -->
  <script src="vendor/jquery/jquery.min.js"></script>

</body>

</html>
Alexander Thomsen
  • 459
  • 1
  • 4
  • 16
  • 1
    Check the browser console (F12). Maybe you get a "cross domain" error. – Moshe Harush Nov 16 '17 at 04:38
  • Change the button `type` to "button", ie ` – Phil Nov 16 '17 at 04:52
  • Also, your `` should come **before** your other ` – Phil Nov 16 '17 at 04:54
  • And one more, sender.net does not appear to allow cross-origin requests. What you're trying to do will not be possible without involving a CORS proxy. – Phil Nov 16 '17 at 04:56
  • Thanks a lot made changes based on your suggestions - at least I see movement in the console now - It says, failed to load the API: No "access-control-allow-origin" header is present on the requested API/email/fname.... Origin "null" is there not allowed access. - So I guess cause I got no CORS, will add it in. – Alexander Thomsen Nov 16 '17 at 05:00

1 Answers1

1

<head>
    <title>test with sender</title>
</head>

<body>

    <h1>This is to test sender.net API "POST" </h1>

    <form>
        <input type="text" name="Fname" placeholder="first name">
        <input type="text" name="Lname" placeholder="last name">
        <input type="email" name="Email" placeholder="email address">
        <button type="button" onclick="JSONTest()"> Let the Post req begin! 
        </button>
    </form>

    <script type="text/javascript">
    JSONTest = function() {
        $.ajax({
            url: "https://app.sender.net/api/",
            method: "POST",
            datatype: "JSON",
            data: {
                method: "listSubscribe",
                params: {
                    api_key: "my key number",
                    list_id: "my id number",
                    emails: ["Email", "Fname", "Lname"],
                    update_existing: true
                }
            },
            success : function(response) {
                console.log(response); // Feel free to Use debugger 

            }
        });
    };
    </script>
Abhishek Dhanraj Shahdeo
  • 1,356
  • 2
  • 14
  • 35