API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  MIME types Supported in API Connect. Does it support CSV in output?

    Posted Fri November 25, 2022 05:04 AM
    Hi,

    I want to convert a JSON response I receive to CSV format in API Connect but I am getting parse issues.

    Request you to confirm the MIME types Supported in API Connect. Does it support CSV in output from API Connect to the Calling App.

    If yes, can you let us know, how can we get this configured to make it work. Thanks!

    ------------------------------
    Kshitij Khanna
    ------------------------------


  • 2.  RE: MIME types Supported in API Connect. Does it support CSV in output?

    Posted Mon November 28, 2022 10:10 AM

    Hi Kshitij,

    With your JSON payload in message.body you should have a message.headers.content-type of application/json.  As part of your code to change the content type you should simply set the content-type header to text/csv

    Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 3.  RE: MIME types Supported in API Connect. Does it support CSV in output?

    Posted Mon November 28, 2022 01:57 PM
    Hi Steve,

    Thanks for your response, I tried but it showed me parsing error in API Connect.

    If you don't mind can you please confirm the following:

    1. Do we need to only set the content type or the apim.output as well as when I receive the response it shows parsing error. Do I need to update the Accept header as well?
    2. Do I need to change the MIME type in the provides section of the API. Also please note in the supported MIME types the csv is not mentioned as per this link. Specifying the MIME types that an API produces - IBM Documentation

    Many Thanks in advance.

    ------------------------------
    Kshitij Khanna
    ------------------------------



  • 4.  RE: MIME types Supported in API Connect. Does it support CSV in output?

    Posted Tue November 29, 2022 09:20 AM

    Hi Kshitij,

    Where are you getting the parsing error?  What gateway are you using (v5/v5c/API Gateway)? How are you converting your JSON to a csv?  Perhaps a cut/paste of the log message showing the parse error would be useful to determine if any GatewayScript you have written is throwing the parse error or if the parse error is coming due to your invoke's backend response or perhaps somewhere else in the framework.  Where are you getting your JSON data in the first place? Posted to your API or perhaps the result of an invoke policy's response? In v5/v5c there is an implicit parse being done by the invoke policy based upon the response content type header, so if it is providing a JSON payload with a non JSON content type that could be part of your issue.

    I'm assuming your conversion of the JSON to .csv is a GatewayScript policy, where you would get message.body and then produce the .csv equivalent.  In v5/v5c or the v10 apigateway apim compatibility module, apim.output will set the content type header for you in addition to setting some other framework specific variables if within v5/v5c, so I would recommend that function.  You do not need to modify the accept header.

    As for the mime type in the API's consumes section, this may be version dependent.  The v5/v5c Gateway does not look at this property.  It will work with the request payload and the request content type header.  If you're using an invoke policy these artifacts will be sent to the backend server and a JSON response will be received and processed.  I would need to test this, but I believe the v10 API Gateway may do some validation of the payload received versus the API consumes property, so if using v10 API Gateway I would specify the application/json if that is what your API is consuming.  I don't believe the produces (response) mime type is validated in either case, but again, I'd need to do some testing there to validate that. 

    Hopefully some more detail will assist in providing you an answer to your issue.
    Best Regards,

    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------