MyCloud Logo

MyCloud API Documentation

Token Model [read-only]

The MyCloud API uses JWT tokens for authorization. JWT (Java Web Token) allows for sessionless authentication, which allows for more scalability, as well as providing a simple method for clients to manage API authentication.

RESTful Calls

Get A Fresh JWT Authentication Token

GET/gettoken

Get a fresh JWT authentication token that can be used for all other API RESTful calls.

Request Parameters

Parameter
Type
Required
Example
Description
apikey
string
Yes
d76a13d4113c4323b74e8d7bf14c9a5e
The apiKey that has been assigned to your account.
secretKey
string
Yes
87bddb3998b44272ab254c6447ed7f2452a1e581241944ea
The secretKey that has been assigned to your account.

Response

Name
Type
Example
Description
token_data
json
{ token: "HS256_encoded_token" }
The JWT token to use in RESTful API requests.

Examples

Getting a JWT Token

Please note, you do not need to use any library to decode your token. The token may be used as-is with your requests. However, by decoding the token, you are able to get it's expiration time, which can help you with managing tokens within your code.

  • PHP
  • C#
  • .NET 4.5+
// https://github.com/kelvinmo/simplejwt
use SimpleJWT\JWT;
use SimpleJWT\Keys\KeySet;
use SimpleJWT\InvalidTokenException;

function get_jwt_token()
{
	$api_key = 'YourApiKey';
	$secret_key = 'YourSecretKey';
	$url = 'https://api.mycloudfulfillment.com/api/v1/gettoken';
	$parameters = array( 'apikey' => $api_key, 'secretkey' => $secret_key );

	$ch = curl_init();

	curl_setopt( $ch, CURLOPT_URL, $url );
	curl_setopt( $ch, CURLOPT_HEADER, true );
	curl_setopt( $ch, CURLINFO_HEADER_OUT, true );
	curl_setopt( $ch, CURLOPT_POST, true );
	curl_setopt( $ch, CURLOPT_POSTFIELDS, $parameters );

	$json_data = curl_exec( $ch );
	$httpStatus = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

	curl_close( $ch );

	$token_data = json_decode( $json_data, true );

	$token = $token_data['token'];

	try {
		$jwt = JWT::decode( $token, $set, 'HS256' );
		$iat = $jwt->getClaim('iat');
		$tokenIssued = $iat;
		$exp = $jwt->getClaim('exp');
		$tokenExpires = $exp;
		$iatTime = \DateTime::createFromFormat( 'U', $iat );
		$expTime = \DateTime::createFromFormat( 'U', $exp );
		$dateUTC = new \DateTime( null, new \DateTimeZone("UTC") );
	} catch ( InvalidTokenException $ex ) {
		$token = NULL;
	}

	return $token
}
C# does not appear to have built-in support for multipart/form-data content.
However you can find a class written for this purpose here:

   https://briangrinstead.com/blog/multipart-form-post-in-c/

If you can provide native C# code that can post the multipart/form-data, without
the need for 3rd party code, please provide the example, and we will put it here.
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StringContent(apikey), "apikey");
form.Add(new StringContent(secretkey), "secretkey");
HttpResponseMessage response = await httpClient.PostAsync("https://api.mycloudfulfillment.com/api/v1/gettoken", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
string json_data = response.Content.ReadAsStringAsync().Result;
//
// Assuming you are using Json.NET: https://www.newtonsoft.com/json
//
dynamic token_data = JsonConvert.DeserializeObject( json_data );
string token = token_data.token;
Using a JWT Token

Once you have retrieved your JWT token, you simply include it in your Authorization header.

  • PHP
  • C#
	...

    curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
		'Authorization: Bearer ' . $token
		)
	);

	...
	...

	request.Headers.Add( "Authorization", "Bearer " + token );

	...