Help using makeWebRequest() please

I'd like to read in a GPX file using makeWebRequest().

I started with the webRequest sample app and got that to work.

I've created a GPX file for testing, placed in in a Google Drive, set sharing to anyone with the link, and verified with a browser that the link works to read the file.

I'm now trying to read that file using makeWebRequest() and I get a -400 error indicating "Response body data is invalid for the request type".

I've tried many combinations and variations in the options to the makeWebRequest() call. So far they all have returned -400.

Can someone provide a solution..... what combination of parameters to the makeWebRequest() call will let me read the file ?

Here's the code that makes the call:

//! Make the web request
private function makeRequest() as Void
{
_notify.invoke("Executing\nRequest");

var options =
{ :method => Communications.HTTP_REQUEST_METHOD_GET,
//:headers => { "Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON }, // URL_ENCODED },
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON //TEXT_PLAIN // was TYPE_JSON
};


var reqStr = "">drive.google.com/.../view
System.println("request string = " + reqStr );

Communications.makeWebRequest( reqStr, {}, options, method(:onReceive) );

}

  • GPX is different from JSON which is the format you are trying to import what did you want to do with the GPX file? 

    Try using HTTP_RESPONSE_CONTENT_TYPE_GPX

    Couple of things,  Format of the link i think needs to be direct download so should look something like this

    Also if you want to create a route list in JSON, this file can help it will also convert GPX Route Files, yours appears to be only a list of Waypoints,
  • I'd like to read in Waypoints and courses for use in my app. I currently use settings for waypoint and course entry and would like to also support the use of GPX files for that purpose. From what I've read in the forums CIQ doesn't expose access to waypoints and courses so reading and decoding the contents of a GPX seems like the only approach available, either reading directly into the app using makeWebRequest(), or creating a companion phone app to do that work.

    The GPX file I'm using for testing is just for testing. I'd like to be able to load both waypoints and routes.

    I was hoping to read in the file using CONTENT_TYPE_GPX but quickly found that that option is not available on very many devices. I was heading in the direction of loading the file as a text file and decoding it as needed. Simply can't find a way to get past the -400 error.

    Thoughts ?

  • Yep, ok sounds like your on the right path, JSON gives you more flexibility to create your own Data Scheme, or you can use a GPX File if you want to keep it simple, i ran into the same issue which is why i created the Files in JSON, the Excel link provided will help you create a sample file, but also make sure the link address is direct download (to test when you click the link on PC it should just download the file instead of taking you to the Google site)

    https://apps.garmin.com/en-US/apps/174c8fa1-9ba5-436a-b41b-75a67f984e94 this is the App if you want to see how it works in practice

  • Thanks for all of that.

    At this point I need guidance to get the parameters to the makeWebRequest() call right, so I can download either a GPX file or a plain text file, or a GPX file as a plain text file.

    Do you know what the parameters have to be to accomplish that ?

    Thanks

  • With fit or GPX files, they become persisted content.  Not all devices handle GPX, and not all handle FIT files.  Once on the device they can be used to launch native activities (with exitTo()).  You can not read/use one of these files directly with a CIQ app/

  • Do you want to use route in the device’s normal navigation?

    If so, you can have your app download the file. But you’ll need to download FIT for some devices and GPX for others. You can’t do anything but download these files.

    You can’t get GPX data unless you read it as text. That also means you’ll have to write your own GPX reader.  The file you read might also be too large for IQ to handle.

    For waypoints, you can use JSON and add them to locations (that is what I do).

  • I need to load waypoints and routes into my CIQ app for direct use by the app.

    If there's a way for me to read a simple text file using makeWebRequest() that would be a step in the right direction. 

    Is there a way to do that ?

  • One of the response types is text. 

    Consider using JSON. 

  • You have to create a text file yourself and then download it using HTTP_RESPONSE_CONTENT_TYPE_TEXT_FLAIN.

  • I’d recommend you translate your gpx files into json. You will have to decode the data somewhere, and it’s probably easier to do on your server than in MonkeyC as you can use DOM XML libraries to access the GPX data.

    Consider converting XML date/time to Unix timestamps and lat/Lon to integer “semicircles” (degrees * 0x7fffff/180)