The Infor Communities is globally accessed system by Infor and its customers, please do not post or upload any content that could be deemed as sensitive, confidential or subject to any data regulation requirements. If you are unsure whether or not the content contains sensitive, confidential or has any data regulation requirements, please seek the advice of your internal security, legal, and compliance experts.

Passing data to a web service

I am having trouble passing data to a Mingle web service that I am trying to access via a script for MWS410. I've looked around and compared my code to others trying to consume a Post web service but I haven't been able to find a solution that works. My question is what is the correct way to send data to a web service using H5 SDK tool?

var request = {
        url:reqUrl,
        dataType : 'json',
        method:'POST',
        contentType: 'application/json',
        data: JSON.stringify({"MessageText" : "this Message"})
        };
        IonApiService.Current.execute(request).then(function(response) {
            if (!response.data.ErrorList{
                console.log("---------------SUCCESS------------------");
                console.log(response);
            }
            else {
                for (var _i = 0, _a = response.data.ErrorList; _i < _a.length; _i++{
                    var error = _a[_i];
                    console.log("ERROR");
                    console.log(error.Message);
                }
            }
       })
  • Hi, 

    You are using a JavaScript directly in H5. The H5 SDK is for building applications and this is a JavaScript. Any time I hear H5 SDK I think of the github project https://github.com/infor-cloud/m3-h5-sdk, and this is not it since you have the IonApiService.Current this is an attempt to call using the IonApiService class that exists in H5 for Cloud.

    What is the version if M3 that you are on?

    You can only call ION APIs in M3 CE, so I assume that is it. What is the service / API in Mingle, that you are trying to call? What is the input? What is the URL? Screenshot of it's documentation in ION API?

    1. {"MessageText": "This message "}. You have to remove the JSON.stringify, you should set an object, not a string representation of an object.

    var request = {
            url:reqUrl,
            dataType : 'json',
            method:'POST',
            contentType: 'application/json',
            data: {"MessageText" : "this Message"}
            };
    2. reqUrl should be a relative URL if I'm not mistaken, what you see in the ION API Swagger documentation for the API, for example User/Detail. 
    The IONAPIURL base URL is known by H5 and the IONAPIService so you just need the last part of it.
    3. You need to have a callback for when the promise is rejected as well. You only have a success handler in your code.
     IonApiService.Current.execute(request).then(function(response) {
    // there is a response that might have an data.ErrorList here
        console.log("myscript: success callback")}, 
       function(err){
       console.log("myscript: there was an http error");
    });
    4. Check the Network log and the console log for error and more information.
    Since you are not sharing more information it's hard to know why the call actually fails. User the browser developer tools and check both the console and network tab, always.
  • The mingle API I am trying to pass data to is /SocialService.Svc/User/{userGUID}/ColleagueFeeds/{colleagueUserGUID}.

    You are correct I am using  M3 Cloud edition.Here is the URL I am using:

    var reqUrl =IonApiService.Current.getBaseUrl() + "/" + _this.mingleEndpoint + "/SocialService.Svc/User/" + _this.userGUID + "/ColleagueFeeds/" + colleagueUserGUID;
    The URL looked correct because when I check the Network tab I saw the requested URL and the status is 200 with a status text Sucess.
    There are three required parameters in this web service userGUID (path),colleagyeUserGUID(path), and the message(body). I believe I am using a relative URL to access the web service. 

    When I call the Webservice the response I usually get is:

    {
    [functions]: ,
    __proto__: { },
    AlertCategoryList: null,
    AlertList: null,
    ErrorList: [
    0: {
    [functions]: ,
    __proto__: { },
    Code: 300,
    Message: "Message text is missing",
    Severity: 1
    },
    length: 1
    ],
    Feeds: null,
    MoreAlerts: false,
    MoreFeeds: false,
    MoreTasks: false,
    RefreshIdentifier: null,
    Status: 2,
    TaskCategoryList: null,
    TaskList: null
    }

  • You are calling the API and receiving a response. If you remove the JSON.Stringify I hope that it works for you. You can try in the ION API application to run the API through the documentation page, look for a button called "Try it out".

    There you can try different inputs. But change to use JSON (and that the response should be JSON).

    If you would like to show the response then you should copy the response from the Network tab in developers tools, not the JavaScript object from the console log that you have. It's a bit confusing to see functions mixed with the data.

    If you remove the JSON.Stringify then the request object will look correct.

    The ION API Service takes a relative path. But as you said the call itself is successful and it's Mingle that is complaining regarding the input. Having cleared that part out the question now is more related to the Social API itself and how to post a message to a collegue. 

  • JSON.stringify has been removed, the path has been changed to be a relative path and it is making a connection to the server. 

       Despite these changes my message is not getting passed correctly.Is there any documentation you can point me to that has an example of a post web service that passes data? the sample ones we currently have do not have such an example. 

          I have tried using the "Try it out" function and it works every time, I've also consumed the web service via the H5 Application tool but when it comes to the H5 SDK it has been unsuccessful. Posting a message to a colleague is possible so the question still remains, How do  I pass data to  ION web services via the H5 SDK tool used in M3 CE?

    Belowis the current code I am using as well as the contents of the Network tab.

     var reqUrl =_this.mingleEndpoint + "/SocialService.Svc/User/" + _this.userGUID + "/ColleagueFeeds/" + colleagueUserGUID;
     var request = {
            url:reqUrl,
            dataType : 'json',
            method:'POST',
            contentType: 'application/json',        
                data:{"MessageText": "this Message"}
            
            };
            IonApiService.Current.execute(request).then(function(response) {
                // there is a response that might have an data.ErrorList here
                    console.log("myscript: success callback")
                    console.log(response);
                    for (var _i = 0, _a = response.data.ErrorList; _i < _a.length; _i++{
                        var error = _a[_i];
                        console.log("ERROR");
                        console.log(error.Message);
                    }
                
                }, 
                   function(err){
                   console.log("myscript: there was an http error");
                });
    The following is from the Network tab
    Request URL
    Name Protocol Method Result Content type Received Time Initiator
    mingle-ionapi.inforcloudsuite.com/.../61d25f51-de38-4741-a220-83f146bb6dcd HTTP/2 POST 200 application/json 263 B 209.04 ms XMLHttpRequest

    Request Headers:
    Accept: application/json
    Accept-Encoding: gzip, deflate
    Accept-Language: en-US, en; q=0.5
    Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkluZm9yQWNjZXNzVG9rZW5TaWduaW5nQ2VydGlmaWNhdGUtMTU3NjkxMTAyMyJ9.eyJzY29wZSI6IiIsImp0aSI6IldtZ2lKTGZFdEU2WWhLalhzbnF4OEFFWHJ2N2JpY3Z0bzBnaCIsIklkZW50aXR5MiI6IjZjMzVlMmNhLTc3MDctNGNmMC1hZjE4LTEyMzMwM2U4MmIwYiIsIlRlbmFudCI6IlRFS05PUkFQRVhDT01QQU5fVFNUIiwiU1NPU2Vzc2lvbklEIjoiVEVLTk9SQVBFWENPTVBBTl9UU1R-NzAxM2I3M2UtOTliNy00MjYyLWI4NDYtYzFmNjA3NWYwZDAyIiwiRW5mb3JjZVNjb3Blc0ZvckNsaWVudCI6ImZhbHNlIiwiZXhwIjoxNTg4MDkwMDMyfQ.fcZS6Xu63GP1Lp_0fj9ShIkYLDF-Wq3Fj2eoliIwuj1ExkX5W2HDZJpsCJAHZaQ5ye3wMCWeF_xYvqGYoJp8rsvDMs_FFCuVPdZQQsRPn-SeTjwlsMRzFTaVE3YixPGfkTuyjDHnm4jDKrZE3wSfPMjQqcqCJZlYzjLzgpEz_0FzlSscIrmViB0By00C87Wh-R1zgxE6xa7b5e8dC4eJDrtax0S7RlDD-KBRSlF-j9vUIXTcQUhuCotVINjPTaUNL4lGPxz4QBB8gO-dSVkvT6aF-PInya0Dc-IldVkh8RpZJxdrTlwl_rPdy5VNgXkL8hNDeT12VD28e_2V1Bxc5Q
    Cache-Control: no-cache
    Content-Length: 24
    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    Host: mingle-ionapi.inforcloudsuite.com
    Origin: m3prduse1.m3.inforcloudsuite.com
    Referer: m3prduse1.m3.inforcloudsuite.com/.../
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

    Response Headers:
    access-control-allow-credentials: true
    access-control-allow-origin: m3prduse1.m3.inforcloudsuite.com
    cache-control: no-cache, no-cache, no-store, max-age=0, must-revalidate
    content-length: 263
    content-type: application/json
    date: Tue, 28 Apr 2020 14:17:15 GMT
    expires: -1
    pragma: no-cache,no-cache
    server: ionapi-12.0.44.85
    strict-transport-security: max-age=31536000; includeSubDomains=true
    vary: Origin
    x-envoy-decorator-operation: ionapi_gateway
    x-frame-options: SAMEORIGIN
    x-response-time: 133
    x-transaction-id: 5083eb02-6c17-95d6-b33f-8ad8de3821eb

    Response
    {
    "ErrorList": [{
    "Code": 300,
    "Message": "Message text is missing",
    "Severity": 1
    }],
    "Status": 2,
    "AlertCategoryList": null,
    "AlertList": null,
    "Feeds": null,
    "MoreAlerts": false,
    "MoreFeeds": false,
    "MoreTasks": false,
    "RefreshIdentifier": null,
    "TaskCategoryList": null,
    "TaskList": null
    }
  • Hi,

    I think I spotted the issue. Perhaps it is the quotes on  "MessageText" that is the issue here.

    First you should look at the documentation. There is no datatype and additional headers needs to be added as key values. If you use TypeScript and the sample in the KB below when you would have spotted that issue in VisualStudio or Visual Studio Code.

    https://www.inforxtreme.com/espublic/EN/AnswerLinkDotNet/SoHo/Solutions/SoHoViewSolution.aspx?SolutionID=1909067

    interface IonApiRequest {
    url: string;
    method: string;
    responseType?: string;
    record?: {[key: string]: any};
    data?: any;
    cache?: boolean;
    headers?: {[key: string]: string};
    }

    The request should look like this (TypeScript)

    let request: IonApiRequest = {
      url: reqUrl,
      responseType: "application/json", 
      method: "POST",
      data: { MessageText: message },
       headers: {
        contentType:"application/json"
       }
    };

    Perhaps it is the quotes on  "MessageText" that is the issue here. I did not think about it since it's valid JSON, but not the way you write an object in JavaScript.
    JavaScript:
    var request = {
       url: reqUrl,
       responseType: "application/json",
      method: "POST",
      data: { MessageText: message },
       headers: {
        contentType: "application/json"
       }
    };
    If there is still an error message I suggest that you take the result of the working "try it out" and the Script call in you script and compare them line by line.
  • Please also note that it is the SocialGuid that needs to be passed to the API and not the IFS GUID. It's also the case that you must have the collegue in your collegue list for this to work.

  • Perfect Thank you, adding headers content type worked.