Contents
Authentication
There are two ways to send an authenticated request to the MapLarge API. You can request a temporary access token or you can send your user name and password directly with your request.
Both methods are very similar. The only difference is that tokens will expire in the future and your password can only be changed manually. This is a security advantage when using a token compared to using your password directly.
Tokens work just like a password so they should be stored securely. Access tokens may expire at any time in the future.
Request URL:
//my.maplarge.com/auth/login?mluser=email@your.com&mlpass=your_password
Successful Response
{ "success": true, "user": "root_user@ml.com", "token": "-306453411_1435368558", "errors": null }
Unsuccessful Response
{ "success": false, "user": null, "token": null, "errors": [ "The password is incorrect for this user." ] }
GET using Token
//my.maplarge.com//Remote/CreateTableSynchronous? &account=test &tablename=testtableA5345 &fileurl=//domaingoeshere.net/census_states.csv &mltoken=your_token &mluser=your_username
GET using Password:
//my.maplarge.com//Remote/CreateTableSynchronous? &account=test &tablename=testtableA5345 &fileurl=//domaingoeshere.net/census_states.csv &mluser=email@your.com &mlpass=your_password
The only time a POST request is required is during file uploads. The web services API expects the POST to be in the same format as a browser file upload. Here are some code examples to get you started.
File Upload
string url = "//my.maplarge.com/Remote/CreateTableWithFilesSynchronous?mltoken=token&mluser=your_username&account=test&tablename=test123"; string filePath = @"E:\Maplarge\myfile.csv"; byte[] responseArray = wc.UploadFile(url, filePath);
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.*; public class PostExample { //This example uses Apache HttpClient. http://hc.apache.org/ MultipartEntityBuilder builder = MultipartEntityBuilder.create(); HttpEntity entity = builder.build(); HttpPost request = new HttpPost("http://my.maplarge.com/Remote/CreateTableWithFilesSynchronous?mltoken=your_token&mluser=your_username&account=your_account&tablename=test123"); request.setEntity(entity); CloseableHttpClient client = HttpClients.createDefault(); try { HttpResponse response = client.execute(request); HttpEntity responseEntity = response.getEntity(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); // TODO Auto-generated catch block e.printStackTrace(); } } }
url = '//my.maplarge.com/Remote/CreateTableWithFilesSynchronous?mltoken=token&mluser=your_username&account=test&tablename=test123' r = requests.post(url, files={'myfile.csv': open('myfile.csv', 'rb')})