Page 1 of 1

API Express - Hooking API express to sendGrid

Posted: Fri Apr 14, 2017 5:56 pm
by Bruce Stuart

Hello and Happy Friday,

I'm trying to take a service that I formerly had working inside my apps that called the SendGrid Api directly. (Set up a rest service and completed the parameters, etc.).

The beauty of this approach has been negated by the recent 4.0 library implementation which essentially forces you to move these services to API express or to server code.

I'd prefer the API express method - if I could just figure out a way to actually work the API express to accomodate a critical requirement.

I'm using Sendgrid to send HTML formatted emails that 'look nice' to the consumer. In order to do this - you must send the parameters to sendGrid as the BODY (the length exceeds the maximum length for sending as a query paramater - so therefore BODY must be used).

Overall I have 2 issues that I could use immediate assistance for - as there really isn't any documentation (**I've listened to the YouTube videos - no real mapping is done - especially moving body of the API Express request to the body of the REST call).

Issue 1: Rest Call inside my 'project' tests correctly. When I run the overall test it fails.

Failure In Test Mode:

So - Error from Test of the API Express service:

Image

Prior to testing the overall API Express service - here's the success of the REST Component when tested separately.

Image

Issue 2: Moving the BODY from the call from the Application to the API express (where my formatted HTML would live as well as the other required parameters) to the BODY of the call to SENDGRID (or any other API where you need to call service with a BODY parameter)....

So - in this image - it's Arrow labeled #3 - what goes here?

Image

I've used the mapping component - as shown here - but it's a huge head scratcher on how to use what's been mapped as input into the JSON for the body??

Image

Can you help? This is NOT an API specific question - as there are 4 other API calls that I need to do this with (For example an API call to the Apple Store to validate an in AppPurchase - breaks with the new release - and requires the SAME mapping of body of one request from the API express inbound - to the REST call - OUTBOUND.


API Express - Hooking API express to sendGrid

Posted: Fri Apr 14, 2017 7:26 pm
by Bruce Stuart

Well - In case anyone else runs into this issue - I've solved it - so - rather than deleting it - I'll leave the resolution here for others to consume in case they encounter a similar issue.....

  1. In the parameters - anything you enter as a 'hard coded value' - like your authorization key, etc. - Needs to have quotes around it. So - in my photo above - the header content/type - the parameter must be "application/json" - not application/json - without quotes - which is what I typed.

  2. In the body - that you forward on to your rest/API - you must type the JSON object - the way the receiving API wishes to see your JSON object - and you can use the inbound parameters from your inbound body - as 'code' to create this.

    Example of a correctly completed JSON mapping from my inbound BODY - shown below:

    Image