Testing API POST does not work

Hi,
I´m testing the API from a console applicarion using C#.
The GET method works fine I got the request bak from Hello World.
POST tour method does not work for me when testing with the example you are providing, is the format of the postData incorret or something else?
I´m getting error code (400) here is my code:


        string strUrl = string.Format("https://api.routexl.com");
        WebRequest requestObjPost = WebRequest.Create(strUrl);
        requestObjPost.Method = "POSTr";
        requestObjPost.Credentials = new NetworkCredential(userName, passWord);
        requestObjPost.ContentType = "application/json";
        string postData = "locations=[{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.05429\",\"lng\":\"4.248618\"},{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.076892\",\"lng\":\"4.26975\"},{\"address\":\"Uden, The Netherlands\",\"lat\":\"51.669946\",\"lng\":\"5.61852\"},{\"address\":\"Sint-Oedenrode, The Netherlands\",\"lat\":\"51.589548\",\"lng\":\"5.432482\"}]";

        using (var streamWriter = new StreamWriter(requestObjPost.GetRequestStream()))
        {
            streamWriter.Write(postData);
            streamWriter.Flush();
            streamWriter.Close();

            var httpRespose = (HttpWebResponse)requestObjPost.GetResponse();

            using (var streamReader = new StreamReader(httpRespose.GetResponseStream()))
            {
                var JSonresult = streamReader.ReadToEnd();
            }
        }

I corrected Method to POST and now I´m getting error (404) not found

We’re no C# programmers, but you may want to try these adjustments:

  1. strUrl = string.Format("https://api.routexl.com/tour")
  2. requestObjPost.Method = "POST" (without the trailing r)
  3. requestObjPost.ContentType = "application/x-www-form-urlencoded"

works fine I´m getting the result, thanks for the quick respons!

1 Like

The example your are providing for the tour is not a valid JSON when validated on https://jsonlint.com/
please check it.

locations = [{
“address”: “The Hague, The Netherlands”,
“lat”: “52.05429”,
“lng”: “4.248618”
}, {
“address”: “The Hague, The Netherlands”,
“lat”: “52.076892”,
“lng”: “4.26975”
}, {
“address”: “Uden, The Netherlands”,
“lat”: “51.669946”,
“lng”: “5.61852”
}, {
“address”: “Sint-Oedenrode, The Netherlands”,
“lat”: “51.589548”,
“lng”: “5.432482”
}]

41

It seems to validate fine. Can you double check?

It validates when editing the string, copy/paste does not work.
Now I´m working with som other test data from the real world but I get error 409, bellow is the locations I´m posting:

locations =[{“address”: “10002”, “lat”: “59,4791843”, “lng”: “18,3013905”}, {“address”: “10091”, “lat”: “59,3071596”, “lng”: “18,0725852”}, {“address”: “10113”, “lat”: “59,7973677”, “lng”: “17,4435512”}, {“address”: “10113”, “lat”: “59,7973677”, “lng”: “17,4435512”}, {“address”: “10230”, “lat”: “59,2”, “lng”: “17,7333”}, {“address”: “10251”, “lat”: “59,4446719”, “lng”: “18,0214225”}, {“address”: “10260”, “lat”: “59,8585”, “lng”: “17,6454”}, {“address”: “10260”, “lat”: “59,8585”, “lng”: “17,6454”}, {“address”: “10325”, “lat”: “59,56325”, “lng”: “18,24031”}, {“address”: “10331”, “lat”: “59,8585816”, “lng”: “17,6389246”}, {“address”: “10361”, “lat”: “59,5152204”, “lng”: “18,0908499”}, {“address”: “10458”, “lat”: “59,4695535”, “lng”: “18,3073016”}, {“address”: “10468”, “lat”: “59,8610119”, “lng”: “17,4367243”}, {“address”: “10498”, “lat”: “61,3838898”, “lng”: “15,8124737”}, {“address”: “10516”, “lat”: “59,8459562”, “lng”: “17,5923106”}, {“address”: “10572”, “lat”: “59,2847953”, “lng”: “17,9933598”}, {“address”: “10680”, “lat”: “59,5122484”, “lng”: “17,6532968”}, {“address”: “10743”, “lat”: “59,14972”, “lng”: “18,11667”}, {“address”: “10759”, “lat”: “60,03004”, “lng”: “17,55203”}, {“address”: “10782”, “lat”: “59,1726697”, “lng”: “18,1685527”}, {“address”: “10782”, “lat”: “59.1726697”, “lng”: “18.1685527”}]

  1. Copying the string can have a side-effect. It may change the quote character, e.g. "xxx" to “xxx”. This effectively makes the string no longer validate as JSON.

  2. In your locations many lat and lng values are formatted as numbers with a comma as decimal seperator. Our API expects a dot as decimal seperator.

Now all records has dot as decimal separator instead of comma, but still gertting error (409 - Conflict) bellow is the post string:

locations =[{“address”: “10002”, “lat”: “59.4791843”, “lng”: “18.3013905”}, {“address”: “10091”, “lat”: “59.3071596”, “lng”: “18.0725852”}, {“address”: “10113”, “lat”: “59.7973677”, “lng”: “17.4435512”}, {“address”: “10113”, “lat”: “59.7973677”, “lng”: “17.4435512”}, {“address”: “10230”, “lat”: “59.2”, “lng”: “17.7333”}, {“address”: “10251”, “lat”: “59.4446719”, “lng”: “18.0214225”}, {“address”: “10260”, “lat”: “59.8585”, “lng”: “17.6454”}, {“address”: “10260”, “lat”: “59.8585”, “lng”: “17.6454”}, {“address”: “10325”, “lat”: “59.56325”, “lng”: “18.24031”}, {“address”: “10331”, “lat”: “59.8585816”, “lng”: “17.6389246”}, {“address”: “10361”, “lat”: “59.5152204”, “lng”: “18.0908499”}, {“address”: “10458”, “lat”: “59.4695535”, “lng”: “18.3073016”}, {“address”: “10468”, “lat”: “59.8610119”, “lng”: “17.4367243”}, {“address”: “10498”, “lat”: “61.3838898”, “lng”: “15.8124737”}, {“address”: “10516”, “lat”: “59.8459562”, “lng”: “17.5923106”}, {“address”: “10572”, “lat”: “59.2847953”, “lng”: “17.9933598”}, {“address”: “10680”, “lat”: “59.5122484”, “lng”: “17.6532968”}, {“address”: “10743”, “lat”: “59.14972”, “lng”: “18.11667”}, {“address”: “10759”, “lat”: “60.03004”, “lng”: “17.55203”}, {“address”: “10782”, “lat”: “59.1726697”, “lng”: “18.1685527”}, {“address”: “10782”, “lat”: “59.1726697”, “lng”: “18.1685527”}]

When we copy the locations and replace the curly quotes with straight ones, we can get a route in Postman without any problem:

If you share your code or a screenshot here, we can check in more detail.

When dubugging In the C# code the variable routeData string has the straight quotes :slight_smile:

Try without the space after the locations key:

string routeData = "locations=[";

Also, check your previous code is now:

streamWriter.Write(routeData);

Lastly I was able to get a correct response but it does not work when I send a request with 20 adresses, my subscription is today the free acount which supports upp to 20 stops per route, I´m able to send only 10???

image

The API is indeed limited to 10 locations for the free users. That’s mentioned on the same page.

And, we also have a fair use policy.

I choosed to evaluate RouteXL when I saw in the pricing page that it supports up to 20 stops per route and woul like my free subscription to support that number of stops under the project developement

The website has 20 locations and the API has max 10 locations in the free plan, as stated on the pricing page. If you need more locations per route, you’ll need to upgrade your account.