. . .

SDK download via REST API with cURL and Java

In this article we describe how to download the SDK that's tailored to your app via REST API.

After you created an account, an app and classes in the dashboard, there are two ways you can download the SDK. One way is to do this in the dashboard. But there's another way:

As with everything that you can do in the dashboard, you can download the SDK via REST API as well. So you can execute the whole procedure pro-grammatically and thus automate it.

images/download/attachments/8389053/SDK-Download-via-REST.jpg

The REST resource for the SDK is described in our REST API documentation:

http://apiomat.org/apidocs/index.html#!/customers/getSDK_get_19

So you get the zipped SDK after a GET request to the URL https://apiomat.org/yambas/rest/customers/{customerName}/apps/{appName}/sdk/ with the system as parameter.

{customerName} gets replaced by your user name, {appName} gets replaced by the name of your app and {lang} gets replaced by one of the supported platforms / programming languages: Android, Objective C, Python, PHP, Java, Javascript.

The parameter for the used system gets appended to the url: …/sdk/{lang}?usedSystem={System}.

{System} can be TEST, STAGING or LIVE.

Let's get to a concrete example:

For this example we use cURL. It's integrated into most common Linux distributions and Mac OS X and you can download it for Windows on the developer website.

curl https://apiomat.org/yambas/rest/customers/exampleCustomer/apps/exampleApp/sdk/java?usedSystem=TEST \
-u user@domain.com:password -H "X-apiomat-apikey:1234567891234567891" > javasdk.zip

You can execute this step with any HTTP Client which enables you to integrate it into your build process.

In Java it can be done with the Apache HttpClient:

public class ExampleClass
{
private final String host = "apiomat.org";
private final String url = "https://apiomat.org/yambas/rest/customers/exampleCustomer/apps/exampleApp/sdk/java?usedSystem=TEST";
private final String apiKeyHeader = "X-apiomat-apikey";
private final String apiKey = "1234567891234567891";
private final String user = "user@domain.com";
private final String pw = "password";
private final String filename = "javasdk.zip";
 
public void downloadSdk( )
{
try
{
// create client and request
CloseableHttpClient httpClient = HttpClients.createDefault( );
HttpGet httpGet = new HttpGet( this.url );
// add headers
String credentials = this.user + ":" + this.pw;
String encodedAuth = "Basic " + new String( Base64.encodeBase64( credentials.getBytes( "UTF-8" ) ), "UTF-8" );
httpGet.addHeader( "Authorization", encodedAuth );
httpGet.addHeader( this.apiKeyHeader, this.apiKey );
CloseableHttpResponse response;
// execute method
response = httpClient.execute( httpGet );
// write response content to disk
OutputStream output = new FileOutputStream( this.filename );
try
{
response.getEntity( ).writeTo( output );
}
finally
{
response.close( );
output.close( );
}
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
}

After that you can go ahead and use the SDK to connect to and communicate with your app backend.

* link only available in Enterprise Documentation