SendGrid API

So, I’m trying to code a POST action to the SendGrid platform.

The main problem I’m having is that the API have arrays inside it’s data input. So, how do I create arrays for the variables each array have? I can’t find a way for it. I tried using the API form or using the Server Connect method (basically the same), but I can’t find a way to create those arrays.

The request body is:

(https://sendgrid.com/docs/API_Reference/api_v3.html)

The first example in that doc is the “personalization” array which includes the “to” and “dynamic_template_data” arrays.

Hi Carlos,

Unless something has changed in the last couple months, the way to get this done is by opening the file in the editor and manually entering what you need. Build as much as you can in the editor and then enter the arrays and other complex objects in the editor. It can be tricky to get the right syntax for the values, but I don’t think there is anything impossible, just challenging. :neutral_face:

1 Like

I’ve tried that but it’s not working correctly. I’ve modified the file but now wappler won’t open the file.

In the screenshot the file that wappler shows me is not the one that I’ve modified manually

When that happens it means you have made invalid changes, which is easy to do. You have to be extremely careful with the syntax and if the editor does not recognize the file, undo the changes and try again.

1 Like

@George @Teodor I see a lot of posts lately about this topic (limitations in the visual editor when it comes to nested JSON apis). Are you guys planning to extend the functionality of wappler so that we don’t have to fiddle in the code?

4 Likes

@salvuccicarlos , how did you achieve this. I’m exactly in the same position as you. I guess we have to open the php file and add this array inside. Kindly advise. Thanks.

Hello! This is the my API server connect text:

Beware of the SEND GRID API TOKEN value and the TEMPLATE ID value

    <?php
require('../../../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
  "settings": {
    "options": {}
  },
  "meta": {
    "options": {},
    "$_GET": [
      {
        "type": "text",
        "name": "email"
      },
      {
        "type": "text",
        "name": "departamento"
      },
      {
        "type": "text",
        "name": "periodo"
      },
      {
        "type": "text",
        "name": "edificio"
      },
      {
        "type": "text",
        "name": "pdf"
      }
    ]
  },
  "exec": {
    "steps": {
      "name": "SendGrid",
      "module": "api",
      "action": "send",
      "options": {
        "url": "https://api.sendgrid.com/v3/mail/send",
        "method": "POST",
        "headers": {
          "Authorization": "Bearer SEND GRID API TOKEN",
          "Content-Type": "application/json"
        },
        "data": {
          "personalizations": [
            {
              "to": [
                {
                  "email": "{{$_GET.email}}"
                }
              ],
              "dynamic_template_data": {
                "departamento": "{{$_GET.departamento}}",
                "edificio": "{{$_GET.edificio}}",
                "periodo": "{{$_GET.periodo}}",
                "pdf": "{{$_GET.pdf}}"
              },
              "subject": "Envio de expensas"
            }
          ],
          "from": {
            "email": "noreply@hotmail.com.ar",
            "name": "Mail Name"
          },
          "reply_to": {
            "email": "example@hotmail.com",
            "name": "Mail Name"
          },
          "template_id": "TEMPLATE ID"
        },
        "schema": [],
        "dataType": "json"
      },
      "output": true,
      "meta": [
        {
          "type": "array",
          "name": "data"
        },
        {
          "type": "object",
          "name": "headers"
        }
      ],
      "outputType": "object"
    }
  }
}
JSON
);
?>
1 Like

Thank you very much, got it :+1:t4:

1 Like

Wappler made it easy with Wappler 2.4.3 version through the JSON editor to add dynamic data, for eg in Server API Connector… amazing, thanks @George @Teodor @patrick! This makes the above asks easier and straight-forward in the latest version.

2 Likes