14
Views
2
Comments
JSON data not sent while sending API Request in Reactive Web
Question
Application Type
Reactive
Service Studio Version
11.10.3 (Build 36712)

I am trying to consume a REST API from SendGrid and the endpoint is https://api.sendgrid.com/v3/mail/send. I have done a test and it worked. This API method is then used in a Server Action called "SendConnectEmail", which in turn is consumed from another module.

This API method ("PostSend") consist of the following inputs:
- Request (JSON Data Structure as keyed in to the test)
- ContentType (default to "application/json")
- Authorization (contains the Authorization token string)

The Server Action ("SendConnectEmail") consist of 2 inputs:
- Email
- Message
and a local variable "Data" with the Data Type being the same as that of the Request input in the API method.

The Server Action "Assign" the 2 inputs into "Data" and then calls "PostSend" and passed "Data" into the "Request" parameter.

However, when the request is sent, I received a 400 Bad Request error. I have checked the logs and realized that the body sent was empty.

POST https://api.sendgrid.com/v3/mail/send HTTP/1.1
User-Agent: OutSystemsPlatform
Content-Type: application/json; charset=UTF-8
Authorization: [Token string removed]
Host: api.sendgrid.com
Content-Length: 2

{}

HTTP/1.1 400 Bad Request
Connection: keep-alive
Access-Control-Allow-Origin: https://sendgrid.api-docs.io
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl
Access-Control-Max-Age: 600
X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html
Content-Length: 980
Content-Type: application/json
Date: Sun, 27 Dec 2020 17:26:02 GMT
Server: nginx

I have tried debugging and inspected the assigning of data to "Data" local variable in "SendConnectEmail" Server Action and it seemed fine as well. When I stepped into "PostSend", in "OnBeforeRequest" callback, I saw that the "RequestText" (which I assume is supposed to be the data) is actually "{}"

I believe that I have followed the standard steps into consuming an API. I have consumed another API and it works but the difference that the one that worked was a GET instead of a POST.

mvp_badge
MVP
Rank: #17

Hi,

It is difficult from your description to see what is wrong, ideally you share the OML or a screenshot of the assign of the Data Local variable to the Request input of the API method.

Regards,

Daniel

mvp_badge
MVP
Rank: #2

Hi Jeremy,

By default, OutSystems doesn't send JSON attributes that are set to their default values. So most likely, you do not correctly fill the Structure Attributes you pass to the REST Method. You could check if this is the case by setting the "Send Default Value" Property of the Structure Attributes to "Yes". The now should appear in the logging, but probably with empty values (or any other value set as default).