# Calling external REST service from Natural Software AG

**URL:** <https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [August 25, 2020, 8:14pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574 "2020-08-25T20:14:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sreesh\_Puthanveetil](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sreesh\_Puthanveetil](https://techcommunity.softwareag.com/u/Sreesh_Puthanveetil)\
**Post date:** [August 25, 2020, 8:14pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/1 "2020-08-25T20:14:11Z")

</div>

We have new requirement that we need to invoke an external REST endpoint from mainframe Natural program. Webmethod integration server is not available in our environment. We have many existing Natural online transactions which invoke wsdl endpoints using SOAP XML protocol. The problem with REST API is that it accepts only JSON string as input . I am not quite sure that REQUEST DOCUMENT to REST endpoint will work or not. I passed JSON statements , but it came back with several errors.I referred many blogs and articles , all are referring to web method integration server. We are using other SOA product which can convert SOAP to JSON and invoke REST API for us, but the overall effort would have been greatly reduced if mainframe could directly invoke REST end points without contacting any middle ware tool.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [August 25, 2020, 8:33pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/2 "2020-08-25T20:33:20Z")

</div>

Can you please be a bit more specific about the “several errors” you receive ?

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 25, 2020, 9:53pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/3 "2020-08-25T21:53:12Z")

</div>

I have passed JSON parameters via REQUEST DOCUMENT from Natural for Windows, so I am confident that it will work from the mainframe.

---

<div class="post-metadata">

**Author:** ![Trentan\_Healey](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/trentan_healey/32/7009_2.png) [@Trentan\_Healey](https://techcommunity.softwareag.com/u/Trentan_Healey)\
**Post date:** [August 25, 2020, 10:15pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/4 "2020-08-25T22:15:04Z")

</div>

I can testify REST calls work well directly from Natural (and via Mainframe with XML=ON), with JSON and Query parms no problems, perhaps provide an example of what is happening and we can all take a look.

---

<div class="post-metadata">

**Author:** ![Sreesh\_Puthanveetil](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sreesh\_Puthanveetil](https://techcommunity.softwareag.com/u/Sreesh_Puthanveetil)\
**Post date:** [August 25, 2020, 11:05pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/5 "2020-08-25T23:05:09Z")

</div>

Thanks every one for clarifying it .I have never done this before and some how got misunderstood that webmethod integrator is mandatory for rest invocation.The error code is 8304 .Error in transport layer.It is actually invoking https endpoint and not sure whether it has anything to do with certificates.I have raised that an issue and once that is resolved I need to try again.I will post the code snippet tomorrow

---

<div class="post-metadata">

**Author:** ![Juergen\_Lind](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Juergen\_Lind](https://techcommunity.softwareag.com/u/Juergen_Lind)\
**Post date:** [September 7, 2020, 11:39am UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/6 "2020-09-07T11:39:17Z")

</div>

Hello Sreesh,  
would you pls. be so kind as to send me an e-mail to juergen.lind (at) [softwareag.com](http://softwareag.com)?  
The way recommended by Adabas&Natural for REST-enablement is via EntireX.  
I’d like to send oyu some info on that way.  
Cheers,  
Juergen

- A&N Product Management -

---

<div class="post-metadata">

**Author:** ![Sreesh\_Puthanveetil](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sreesh\_Puthanveetil](https://techcommunity.softwareag.com/u/Sreesh_Puthanveetil)\
**Post date:** [September 11, 2020, 3:38pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/7 "2020-09-11T15:38:40Z")

</div>

It took some time to resolve the HTTPS issues . We have added the certificates and I am able to get the JSON response back. The next big challenge for me is to parse the big JSON response string . Is there any in-built parser available for JSON ?. We have PARSE XML , but I could not find anything with respect to it in SYSTXT or github. I wonder why we don’t have it yet .We have work around like invoking another service and get it parsed, but it would have been really nice if something is already available in natural itself. I am trying to write parser in natural, but it less likely that any one will accept as solution due to strict project deadline.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [September 11, 2020, 5:03pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/8 "2020-09-11T17:03:00Z")

</div>

Scan your FNAT libraries for “PARSE” and you will see many references in libraries SYSEXINS, SYSEXV, and SYSXTK.

Here is the basic structure of a function retrieving a postal address.

```auto
REQUEST DOCUMENT
   FROM #URL
   WITH USER 'user' PASSWORD 'password'
        HEADER NAME 'Request-Method' VALUE 'GET'
 RETURN PAGE #RESPONSE
        RESPONSE #RC
                                          /* <-- inspect #RC
PARSE XML #RESPONSE INTO PATH #PATH VALUE #VALUE
                                          /* <-- inspect return code/message
    DECIDE ON FIRST VALUE OF #PATH
      VALUE 'address/contact/$'
            ASSIGN #REPLY.#CONTACT = #VALUE
      VALUE 'address/line1/$'
            ASSIGN #REPLY.#ADDR1 = #VALUE
      VALUE 'address/line2/$'
            ASSIGN #REPLY.#ADDR2 = #VALUE
      VALUE 'address/line3/$'
            ASSIGN #REPLY.#ADDR3 = #VALUE
      VALUE 'address/city/$'
            ASSIGN #REPLY.#CITY = #VALUE
      VALUE 'address/state/$'
            ASSIGN #REPLY.#STATE = #VALUE
      VALUE 'address/zip5/$'
            ASSIGN #REPLY.#ZIP5 = #VALUE
      VALUE 'address/zip4/$'
            ASSIGN #REPLY.#ZIP4 = #VALUE
      NONE VALUE
            IGNORE
    END-DECIDE
END-PARSE
IF #REPLY.#ERROR
  THEN
    ASSIGN view.RETURN-CD = #REPLY.#ERR-CD
    ASSIGN view.RETURN-MSG = #REPLY.#ERR-MSG
  ELSE
    ASSIGN view.CONTACT = #REPLY.#CONTACT
    ASSIGN view.ADDR-1 = #REPLY.#ADDR1
    ASSIGN view.ADDR-2 = #REPLY.#ADDR2
    ASSIGN view.ADDR-3 = #REPLY.#ADDR3
    ASSIGN view.ADDR-CITY = #REPLY.#CITY
    ASSIGN view.ADDR-STATE = #REPLY.#STATE
    ASSIGN view.ADDR-ZIP5 = #REPLY.#ZIP5
    ASSIGN view.ADDR-ZIP4 = #REPLY.#ZIP4
END-IF
. . .

```

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [September 11, 2020, 5:22pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/9 "2020-09-11T17:22:22Z")

</div>

@Ralph_Zbrog - I think he’s looking for a JSON parser, which the PARSE XML statement is not. I’m not aware of support for JSON with the REQUEST DOCUMENT statement. You may want to enter a Brainstorm (change/enhancement) request, but it isn’t likely to help you with the current project, nor, due to the EntireX support for REST via wmIS, is it likely to be made available (my opinion only, not official Software AG statement).

Using EntireX with REST support is available to all EntireX customers now and is likely to be the quickest way for you to solve your problem.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [September 11, 2020, 5:57pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/10 "2020-09-11T17:57:41Z")

</div>

This was for one of my clients who asked for JSON support. I was a bit surprised that it worked.

The biggest coding change was in the formatting of the request:

```auto
ASSIGN #TEMP.#CONTACT = view.CONTACT
ASSIGN #TEMP.#ADDR1 = view.ADDR-1
ASSIGN #TEMP.#ADDR2 = view.ADDR-2
ASSIGN #TEMP.#ADDR3 = view.ADDR-3
ASSIGN #TEMP.#CITY = view.ADDR-CITY
ASSIGN #TEMP.#STATE = view.ADDR-STATE
ASSIGN #TEMP.#ZIP = view.ADDR-ZIP
EXAMINE #TEMP.#CONTACT FOR ' ' REPLACE '+'
EXAMINE #TEMP.#ADDR1 FOR ' ' REPLACE '+'
EXAMINE #TEMP.#ADDR2 FOR ' ' REPLACE '+'
EXAMINE #TEMP.#ADDR3 FOR ' ' REPLACE '+'
EXAMINE #TEMP.#CITY FOR ' ' REPLACE '+'
EXAMINE #TEMP.#STATE FOR ' ' REPLACE '+'
*
COMPRESS '?' -
         '&contact=' #TEMP.#CONTACT
         '&line1=' #TEMP.#ADDR1
         '&line2=' #TEMP.#ADDR2
         '&line3=' #TEMP.#ADDR3
         '&city=' #TEMP.#CITY
         '&state=' #TEMP.#STATE
         '&zip5=' #TEMP.#ZIP5
         '&zip4=' #TEMP.#ZIP4
    INTO #REQUEST LEAVING NO SPACE

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:45pm UTC](https://techcommunity.softwareag.com/t/calling-external-rest-service-from-natural-software-ag/232574/11 "2021-04-02T15:45:06Z")

</div>


