0

I tried to connect to the following API https://api.ssg-wsg.sg/grantCalculators/individual. I got the following error "Access to this API has been disallowed". Is there any UAT exist for these skill Future APIs? Thanks!

My subscription [1]: https://i.stack.imgur.com/5ZgiQ.jpg

My code try {

            if (Session["access_token"]==null)
            {
                txtResult.Text = "Generate Token first.";
                    return;
            }                

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.DefaultConnectionLimit = 9999;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
           // string url = "https://mock-api.ssg-wsg.sg/grantCalculators/individual";
            string url = "https://public-api.ssg-wsg.sg/grantCalculators/individual";
            // string url = "https://api.ssg-wsg.sg/grantCalculators/individual";
            // string data = "{\"trainingPartnerUen\":\"198201025C11\",\"courseReferenceNumber\":\"TGS-0026008-ES\"}";
            string data = "{\"trainingPartnerUen\":\"" + txtUEN.Text + "\",\"courseReferenceNumber\":\"";
            data+=txtReferenceNumber.Text+ "\",\"}";
            //url = url + data;
            WebRequest myReq = WebRequest.Create(url);              
            myReq.Method = "POST";
            string accesTocken = Session["access_token"].ToString();
            myReq.ContentType =  "application/json";
            using (var streamWriter = new StreamWriter(myReq.GetRequestStream()))
            { 
                streamWriter.Write(data);
            }
           
            myReq.Headers.Add("Authorization", "Bearer  " + accesTocken);
            var httpResponse = (HttpWebResponse)myReq.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                txtResult.Text=result;
            }             
           


            
        }
        catch (WebException webex)
        {
            WebResponse errResp = webex.Response;
            using (Stream respStream = errResp.GetResponseStream())
            {
                StreamReader reader = new StreamReader(respStream);
                string text = reader.ReadToEnd();
                txtResult.Text = text;
            }
        }
        catch (Exception ex)
        {
            txtResult.Text = ex.Message;
        }
ashif
  • 1
  • 1

2 Answers2

0

Sounds like you are not yet subscribed to the API. I just checked that this API does not require any approval, so you may wish to subscribe to this API and test it out directly.

API swagger: https://developer.ssg-wsg.sg/webapp/docs/product/7KU1xrpxljJZnsIkJP6QNF/group/IUAJ3XXeGEZuk9yGpoUX3/api/JSUVkOlAbD5KS2tpCw9aB/version/pgJTm66XDOVr61ZpCVFf

App development guide: https://developer.ssg-wsg.sg/webapp/guides/6gvz7gEnwU2dSIKPrTcXnq

Other get started guides: https://developer.ssg-wsg.sg/webapp/guides

dao_ying3
  • 11
  • 2
  • Thanks for the reply. I already subscribed the API. But I can not connect to the API from my code – ashif Dec 26 '20 at 07:58
  • Just to confirm it's not a subscription issue, have you tested your key using Postman? Reference: https://developer.ssg-wsg.sg/webapp/guides/6gvz7gEnwU2dSIKPrTcXnq#4-testing-with-oauth-token – dao_ying3 Dec 29 '20 at 06:40
  • Yes. It is successful. Is there any UAT API url for testing? – ashif Jan 01 '21 at 08:44
  • I don't think there is a UAT URL you can use at this point of time, but if your Postman call is working, it should not be an issue with the key. You may try out @druyal96's suggestion or take a look at the sample codes on GitHub. (https://github.com/ssg-wsg/community/tree/master/guides) – dao_ying3 Jan 04 '21 at 10:20
0

I tried running your code and found out the issue is at the following line where there is a double space after Bearer which causes the access token not being identified.

myReq.Headers.Add("Authorization", "Bearer  " + accesTocken);

Solution:

myReq.Headers.Add("Authorization", "Bearer " + accesTocken);
druyal96
  • 1
  • 3