0

My Requirement is to create a JSON for the below xml, and send as POST request to SAP Netweaver adapter.

  • SAP End point URI: /sap/opu/odata/sap/ZPM_MOBILE_SRV/WOHeaderSet
  • Method: POST
  • Payload: 1 operation, 2 materials

XML request which contain two payload operations and material.

  1. operation : WOHeaderOperation
  2. material : WOHeaderMaterial

This code basically contains two sections, one WOHeaderOperation and second for WOHeaderMaterial:

    <?xml version="1.0" encoding="UTF-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <atom:content type="application/xml">
      <m:properties>
         <d:Aufpl>1000000053</d:Aufpl>
         <d:GltrpTms>1425887760</d:GltrpTms>
         <d:GstrpTms>1425887760</d:GstrpTms>
         <d:Auart>PM02</d:Auart>
         <d:Ktext>Test for MAMBO 2</d:Ktext>
         <d:Iwerk>KACT</d:Iwerk>
         <d:Ingrp>KP</d:Ingrp>
         <d:Gewrk>10000359</d:Gewrk>
         <d:Tplnr>KAC-0P5010-PM1</d:Tplnr>
         <d:Arbpl>10000359</d:Arbpl>
      </m:properties>
   </atom:content>
   <atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/WOHeaderOperation" type="application/atom+xml;type=feed" title="WOHeaderOperation">
      <m:inline>
         <atom:feed>
            <atom:entry>
               <atom:content type="application/xml">
                  <m:properties>
                     <d:Vornr>0010</d:Vornr>
                     <d:Ltxa1>Operation 1</d:Ltxa1>
                     <d:Indet>2</d:Indet>
                  </m:properties>
               </atom:content>
            </atom:entry>
         </atom:feed>
      </m:inline>
   </atom:link>
   <atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/WOHeaderMaterial" type="application/atom+xml;type=feed" title="WOHeaderMaterial">
      <m:inline>
         <atom:feed>
            <atom:entry>
               <atom:content type="application/xml">
                  <m:properties>
                     <d:Vornr>0010</d:Vornr>
                     <d:Posnr>0010</d:Posnr>
                     <d:Matnr>340</d:Matnr>
                     <d:Werks>KACT</d:Werks>
                     <d:Bdmng>7.000</d:Bdmng>
                     <d:Meins>PCE</d:Meins>
                     <d:Postp>L</d:Postp>
                  </m:properties>
               </atom:content>
            </atom:entry>
            <atom:entry>
               <atom:content type="application/xml">
                  <m:properties>
                     <d:Vornr>0010</d:Vornr>
                     <d:Posnr>0020</d:Posnr>
                     <d:Matnr>338</d:Matnr>
                     <d:Werks>KACT</d:Werks>
                     <d:Bdmng>10.000</d:Bdmng>
                     <d:Meins>PCE</d:Meins>
                     <d:Postp>L</d:Postp>
                  </m:properties>
               </atom:content>
            </atom:entry>
            <atom:entry>
               <atom:content type="application/xml">
                  <m:properties>
                     <d:Vornr>0010</d:Vornr>
                     <d:Posnr>0030</d:Posnr>
                     <d:Matnr>336</d:Matnr>
                     <d:Werks>KACT</d:Werks>
                     <d:Bdmng>10.000</d:Bdmng>
                     <d:Meins>PCE</d:Meins>
                     <d:Postp>L</d:Postp>
                  </m:properties>
               </atom:content>
            </atom:entry>
         </atom:feed>
      </m:inline>
   </atom:link>
</atom:entry>
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

0

If you want it to be JSON, request it as such:

GET /sap/opu/odata/sap/ZPM_MOBILE_SRV/WOHeaderSet?$format=json

But Gateway will accept both JSON and XML so there is really no need other than your own preference.

Mikael G
  • 712
  • 5
  • 13
  • Thanks for your response Mikael – Dharmendra Singh Jul 09 '15 at 06:06
  • I got xml to create JSON request and send it through worklight adapter – Dharmendra Singh Jul 09 '15 at 06:07
  • Then end point you have is SAP Gateway. It will accept both JSON and XML. What you need to do is to make sure it accept the structure you have in your current XML. The easiest way is to request the same service using a GET request. – Mikael G Jul 09 '15 at 09:56
  • If you need to involve IBM Worklight adapter - do that after you have a successful scenario. Use a REST client, your browser or SAP Gateway client. – Mikael G Jul 09 '15 at 09:58