An error while trying to call rest ION API from H5 SDK "Failed to load resource: the server responded with a status of 400 (Bad Request)"

Trying to call ION API with "POST" method using H5 SDK and the API call needs JSON input.

The call of the API failed and raised an error of "Failed to load resource: the server responded with a status of 400 (Bad Request)"

I tried to pass the JSON input in the body as the following code.
const body = {
         // tslint:disable-next-line:max-line-length
         'SqlQuery': 'SELECT s.SalesTeamID ,s.NameSTRING ,s.DescriptionSTRING ,sn.Neutral as Name ,sd.Neutral as Description from SalesTeam s left join StringGeneric sn on s.NameSTRING=sn.StringGenericID left join StringGeneric sd on s.DescriptionSTRING=sd.StringGenericID order by sn.Neutral',
         'OutputColumnInfo': [
            {
               'Name': 'SalesTeamID'
            },
            {
               'Name': 'NameSTRING'
            },
            {
               'Name': 'DescriptionSTRING'
            },
            {
               'Name': 'Name'
            },
            {
               'Name': 'Description'
            }
         ]
      };
and then set the body in the IIonApiRequest
const request: IIonApiRequest = {
         method: 'POST',
         url: url,
         headers: headers,
         source: this.source,
         body: body,
         responseType: 'json'
      };
Parents
  • Hi,

    Have you tried the API in the Swagger test client for ION API, trying to call the endpoint that you would like to call?

    It could be that the input is in fact invalid so you should try in Postman or in the ION API Tool for the endpoint.

  • Hi Karin,

    There is an update
    ** From Postman there is no issue to call the API even if it's GET or POST

    ** From swagger test client , I was able to call a GET API without any issue , But it failed to call POST API and encountered that following issue "CORS error - Origin is invalid"

    I decided to trace it again from the Code the debug console shows an error "Failed to load resource: the server responded with a status of 400 (Bad Request) " But in fiddler I can find the same error as in swagger 

      

  • The call works, but not through a Browser.

    What system has the service that you are trying to access? Is it a custom API that you manually registered to ION API? You should check in the monitoring functionality in ION API if there are any more hints. It could be that the backend you are calling are making some validation on Origin and it's not allowing the M3 origin.

    But one of the benefits with ION is that you don't get CORS issues. Usually you would see the CORS error in the console when the pre-flight check fails, but this time I think it's the backend that is not configured to allow ION API to connect.

    Looking at the response header, do you have the ION API tracker set? You can share the headers here but you must cover the Bearertoken part so it's not readable.

    What is the Origin header on the request?

    Whatever service you are calling, it has to allow you to connect.

Reply
  • The call works, but not through a Browser.

    What system has the service that you are trying to access? Is it a custom API that you manually registered to ION API? You should check in the monitoring functionality in ION API if there are any more hints. It could be that the backend you are calling are making some validation on Origin and it's not allowing the M3 origin.

    But one of the benefits with ION is that you don't get CORS issues. Usually you would see the CORS error in the console when the pre-flight check fails, but this time I think it's the backend that is not configured to allow ION API to connect.

    Looking at the response header, do you have the ION API tracker set? You can share the headers here but you must cover the Bearertoken part so it's not readable.

    What is the Origin header on the request?

    Whatever service you are calling, it has to allow you to connect.

Children