cancel
Showing results for 
Search instead for 
Did you mean: 

POST Function Import in Gateway Builder

Former Member
0 Kudos

Hi everyone,

I am trying to create a new Function Import in SEGW transaction (Netweaver Gateway Builder).

I have followed different blogs (For example: and managed to create one.

However I am having 2 small differences:

1.  I am trying to make a Http POST Function Import which is a bit different in the way you call the service.

2. I have a parameter with type Edm.Guid.

I have not found any documentation about these 2 specific things.

Here is what I have...

My function and it`s parameters in SEGW:

My metadata:

The URI I am trying with it`s payload:

/sap/opu/odata/sap/MY_SERVICE/AddTransferProducts

with

<?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:DocGUID>
guid’12345678-aaaa-bbbb-cccc-ddddeeeeffff’</d:DocGUID>
     <d:Products>R100000</d:Products>
</m:properties>
</atom:content>
</atom:entry>

With this setup I get the following error when I call the service: 404 not found

Anyone understands why it is not working ? Anyone already got this issue ?

Thank you very much.

Natalie

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ok, got it working.

It was back to POST http method... bad transport from me side.

So it is ok with GET Http method.  I used URI /sap/opu/odata/sap/MY_SERVICE/AddTransferProducts?DocGUID=guid'12345678-aaaa-bbbb-cccc-ddddeeeeffff'&Products='R100000||R100002'

And I get to my breakpoint in the code. But I have to clear the metadata cache every time on both hub and backend!

Thanks for your support!

Answers (1)

Answers (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Natalie,

Function Imports in SAP Gateway does not support request body.

You need to mention parameters in the URI.

Example:

/sap/opu/odata/sap/MY_SERVICE/AddTransferProducts?Products='R100000'&DocGUID=guid’12345678-aaaa-bbbb-cccc-ddddeeeeffff’


For Docu

Find URI Conventions here. Search for 'Service Operations'

URI Conventions | Open Data Protocol


regards

Krishna

Former Member
0 Kudos

Hi Krishna,

Thank you very much for your quick response.

Then what is the meaning of the POST Http Method Type in my first screen shot ?

For this field I have 2 choices: POST and GET. What is the difference ?

Thanks again and regards,

Natalie

kammaje_cis
Active Contributor
0 Kudos

Using GET, you are supposed to model non-modifying operations. (Reservation availability? material in stock? etc)

Using POST you are supposed to model modifying operations. POST requests can be safeguarded using CSRF token protection. (Approve requests, lock user etc.)

Though there is no explicit control and no one is stopping you from doing modifying operation in GET, it is against recommendation.

Former Member
0 Kudos

Great thanks for the information.

Now I get the following error:

The request URI is not valid. The segment 'TransferDetails' refers to an entity set and not to a single entity

Am I missing something ?

Thanks again,

Natalie

kammaje_cis
Active Contributor
0 Kudos

May be you can share the request URL and error log.

Former Member
0 Kudos

I am back to a GET function import.

/sap/opu/odata/sap/MY_SERVICE/AddTransferProducts?DocGUID=guid'12345678-aaaa-bbbb-cccc-ddddeeeeffff'&Products='R100000||R100002'

and I get the error:

kammaje_cis
Active Contributor
0 Kudos

When you changed from POST to GET, hope you have changed the metadata and cleared metadata cache.

If that does not work, can you show me the code implementation.? You should be returning a table, since the return cardinality is N.

Former Member
0 Kudos


Metadata is showing GET method and the cache was cleared.

Here is a snippet of my code

CLASS xxxxx_DPC_EXT, method

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION


    IF iv_action_name EQ 'AddTransferProducts'.

      IF it_parameter IS NOT INITIAL.

*       Read Function import parameters values
        READ TABLE it_parameter
          INTO ls_parameter
          WITH KEY name = 'DocGUID'.

        IF sy-subrc = 0.
          lv_docguid = ls_parameter-value.
        ENDIF.

        READ TABLE it_parameter
          INTO ls_parameter
          WITH KEY name = 'Products'.

        IF sy-subrc = 0.
          lv_concat_products = ls_parameter-value.
        ENDIF.

        SPLIT lv_concat_products AT '||' INTO TABLE lt_products.

*       Save products in the staging table and get product information
        LOOP AT lt_products
          ASSIGNING <lfs_products>.

          ls_transfer_details-matnr =   <lfs_products>-matnr.
         APPEND ls_transfer_details TO lt_transfer_details.

        ENDLOOP.

*       Build the Document Details entity set to return
        LOOP AT lt_transfer_details
          ASSIGNING <lfs_transfer_details>.


          MOVE-CORRESPONDING <lfs_transfer_details> TO ls_entity.
          APPEND ls_entity TO lt_entityset.

        ENDLOOP.

*       Call method copy_data_to_ref and export entity set data
        copy_data_to_ref( EXPORTING is_data = lt_entityset
                CHANGING cr_data = er_data ).

      ENDIF.
    ENDIF.

kammaje_cis
Active Contributor
0 Kudos

Code looks good. Does the control come to DPC_EXT?

Can you try removing || from the URI?

AshwinDutt
Active Contributor
0 Kudos

Hello Natalie,

When you are using Custom Action/Function Import , you need to send the ACTION name ( note : not entity set name ) and parameters required for your action to work ( READ / CREATE / DELETE / UPDATE ).

The URI convention has already been nicely described by Chandra for function import.

example :

/sap/opu/odata/sap/MY_SERVICE/<Your Custom Action Name>?Products='R100000'&DocGUID=guid’12345678-aaaa-bbbb-cccc-ddddeeeeffff’

Same way you can implement Custom Action/Function Import your Create, Delete,Read & Update operation with corresponding HTTP methods.

Regards,

Ashwin

Former Member
0 Kudos

I have tried without the || and I get the same error message.

I have put breakpoints into my DPC_EXT method and I never get to it. 😞

Do I need to implement the GETEntitySet service for TransferDetails ???

Former Member
0 Kudos

This is exactly what I do.

kammaje_cis
Active Contributor
0 Kudos

No you don't have to. Problem has to be with your URI w.r.t metadata. Gateway parser finds something wrong with your URI when it compares with the metadata.