IBM TechXchange Group

 View Only
Expand all | Collapse all

$storageType() extension in API Connect switch policy not detecting request body content type

  • 1.  $storageType() extension in API Connect switch policy not detecting request body content type

    Posted Thu June 29, 2023 07:19 AM
    Edited by EIS Developer Thu June 29, 2023 07:25 AM
    Per https://www.ibm.com/docs/en/api-connect/10.0.1.x?topic=switch-using-policy-condition-editor, I am attempting to use the $storageType([arg]) extension in a switch policy to detect the request body content type (binary, json, stream,or xml).
      - switch:
          version: 2.0.0
          title: switch
          case:
            - condition: ($storageType() = 'binary')
              execute:
                - gatewayscript:
                    version: 2.0.0
                    title: gatewayscript
                    source: |-
                      context.message.body.write('in binary');
                      context.message.header.set('Content-Type', "*/*");
            - condition: ($storageType() = 'stream')
              execute:
                - gatewayscript:
                    version: 2.0.0
                    title: gatewayscript
                    source: |-
                      context.message.body.write('in stream');
                      context.message.header.set('Content-Type', "*/*");
            - condition: ($storageType() = 'json')
              execute:
                - gatewayscript:
                    version: 2.0.0
                    title: gatewayscript
                    source: |-
                      context.message.body.write('in json');
                      context.message.header.set('Content-Type', "*/*");
            - condition: ($storageType() = 'xml')
              execute:
                - gatewayscript:
                    version: 2.0.0
                    title: gatewayscript
                    source: |-
                      context.message.body.write('in xml');
                      context.message.header.set('Content-Type', "*/*");
            - otherwise:
                - gatewayscript:
                    version: 2.0.0
                    title: gatewayscript
                    source: |-
                      context.message.body.write("in otherwise");
                      context.message.header.set('Content-Type', "*/*");
    I have a request that is posting to the API with the above switch policy:
    curl --location 'https://my-api.net/test-switch' \
    --header 'Content-Type: text/plain' \
    --data '@/C:/PathToFile/notes.txt'
    What I found, is regardless of the request body content, the above as well as the curl statements below returns `in stream`.
    curl --location 'https://my-api.net/test-switch' \
    --data '{
    "status":"here"
    }
    curl --location 'my-api.net/test-switch' \
    --data '<?xml version="1.0" encoding="UTF-8" ?>
    <status>here</status>
    '
    What am I doing wrong?



    ------------------------------
    EIS Developer
    ------------------------------



  • 2.  RE: $storageType() extension in API Connect switch policy not detecting request body content type

    Posted Fri June 30, 2023 07:38 AM

    Hii sir httml code 



    ------------------------------
    Gourav Rao
    ------------------------------