Skip to content

Client-key

The client-key is a special token that is required for most PhotoILike API requests. The idea is that each end-user has a unique client-key.

The client-key resource requires several requests which are detailed below.

Client-key creation

Warning

PhotoILike does not store client-key tokens. It is important that they are stored securely because PhotoILike cannot obtain the token of a previously generated client-key.

Request

POST https://api.photoilike.com/v2.0/client-key

Headers

Fields

Key Value
Authorization string
Required
Session token preceded by the word Bearer.

Body of the request

The body of the request contains data with the following structure:

JSON representation

{
    "send": bool,
    "clients": [
        {"name": string, "email": string},
        ...
    ]
}

Fields

Parameter Information
send bool
Optional.
If the field is true, all generated client-keys will be sent to the PhotoILike registered account e-mail address.
clients array
Required.
Array of name-email pairs identifying the client for which the client-key is to be created (maximum capacity of the array in a request is 20).
clients[item].name string
Required.
Name of the customer for whom you want to generate the client-key.
clients[item].email array
Required.
Email account of the customer to whom the client-key is to be generated.

Response to the request

On success, the HTTP status code in the response header is 200 OK and the response body contains an array of generated client-keys.

Representation

[
    {
        "id": string,
        "activated": bool,
        "email": string,
        "name": string,
        "secret" string
    },
    ...
]

Fields

Parameter Information
id string
Identifier with which PhotoILike stores the client-key information.
activated bool
Indicates whether the client-key is enabled for use or not.
name string
Customer name used in the request.
email string
Customer's email used in the request.
secret string
Client-key token. This information must be stored in a safe place because PhotoILike does not store the generated token making it impossible to retrieve or restore it.

Example of a request

curl --request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {YOUR.SESSION.TOKEN}" \
--data '{"send": "True", "clients": [{"name": "client1", "email": "client1@example.org"}, {"name": "client2", "email": "client2@example.org"}]}' \
https://api.photoilike.com/v2.0/client-key 
import requests

header = {
    # Add your token session
    'Authorization': 'Bearer YOUR.SESSION.TOKEN'
}

clients = [
    # Set the right values for your clients
    {'name': 'client1', 'email': 'client1@example.org'},
    {'name': 'client2', 'email': 'client2@example.org'}
]

payload = {
    # If send is true an email will be sent to your email account with all the created client-keys
    'send': True,
    'clients': clients
}

endpoint = 'https://api.photoilike.com/v2.0/client-key'

# Make the request
r = requests.post(endpoint, headers=header, json=payload)

# Response in json format
response = r.json()
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.json.JSONArray;
import org.json.JSONObject;

public class ClientKey {

    public static void main(String []args) throws Exception {

        // add your session token
        String bearerToken = String.format("Bearer %s", "YOUR.SESSION.TOKEN");

        // set the right values for your clients
        JSONObject client1 = new JSONObject();
        client1.put("name", "client1");
        client1.put("email", "client1@example.org");

        JSONObject client2 = new JSONObject();
        client2.put("name", "client1");
        client2.put("email", "client1@example.org");

        JSONArray clients = new JSONArray();
        clients.put(client1);
        clients.put(client2);

        JSONObject payload = new JSONObject();
        // if send is true an email will be sent to your email account with all the created client-keys
        payload.put("send", true);
        payload.put("clients", clients);


        String endpoint = "https://api.photoilike.com/v2.0/client-key";

        // build the request
        HttpURLConnection connection = (HttpURLConnection) new URL(endpoint).openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Authorization", bearerToken);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);

        OutputStream os = connection.getOutputStream();
        byte[] input = payload.toString().getBytes(StandardCharsets.UTF_8);
        os.write(input, 0, input.length);

        // make the request
        BufferedReader br = new BufferedReader(
                new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)
        );
        StringBuilder response = new StringBuilder();

        for (String responseLine = null; (responseLine = br.readLine()) != null; response.append(responseLine.trim()))
            ;

        // Response in json format
        JSONArray json = new JSONArray(response.toString());
    }
}
<?php

  // Add your token session
  $headers = array(
    'Content-Type:application/json',
    'Authorization: Bearer YOUR.SESSION.TOKEN'
  );

  // Set the right values for your clients
  $clients = array(
    array(
      'name' => 'client1',
      'email' => 'client1@example.org'
    ),
    array(
      'name' => 'client2',
      'email' => 'client2@example.org'
    )
  );

  // If send is true and email will be sent to your email account with all the created client-keys
  $payload = json_encode(array(
    'send' => true,
    'clients' => $clients
  ));

  $endpoint = "https://api.photoilike.com/v2.0/client-key";

  $ch = curl_init($endpoint);
  curl_setopt($ch,  CURLOPT_POSTFIELDS, $payload);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  // Make the request
  $result = curl_exec($ch);

  curl_close($ch);

  // Response in json format    
  $response = json_decode($result);
 ?>

Deactivation of client-key

Info

The state of a client key can only change from activated to deactivated. This means that a client key that has been deactivated cannot be activated.

Request

PUT https://api.photoilike.com/v2.0/client-key

Headers

Fields

Key Value
Authorization string
Required
Session token preceded by the word Bearer.

Body of the request

The body of the request contains data with the following structure:

JSON representation

{
    "id": string
}

Fields

Parameter Information
id string
Required
Identifier with which PhotoILike stores the client-key information.

Response to the request

On success, the HTTP status code in the response header is 200 OK and the response body contains an object with the modified client-key.

JSON representation

{
    "id": string,
    "activated": bool,
    "email": string,
    "name": string,
    "timestamp": timestamp
}

Fields

Parameter Information
id string
Identifier with which PhotoILike stores the client-key information.
activated bool
Indicates whether the client-key is enabled for use or not.
name string
Customer name used in the request.
email string
Customer's email used in the request.
timestamp timestamp
Time instant at which the client-key was generated.

Example of a request

curl --request PUT \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {YOUR.SESSION.TOKEN}" \
--data '{"id": "{CLIENT_KEY_ID}"}' \
https://api.photoilike.com/v2.0/client-key 
import requests

header = {
    # Add your token session
    'Authorization': 'Bearer YOUR.SESSION.TOKEN'
}

payload = {
    # Add the id of the client-key to desactivated
    'id': "CLIENT_KEY_ID"
}

endpoint = 'https://api.photoilike.com/v2.0/client-key'

# Make the request
r = requests.put(endpoint, headers=header, json=payload)

# Response in json format
response = r.json()
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.json.JSONArray;
import org.json.JSONObject;

public class ClientKey {
    public static void main(String []args) throws Exception {
        // add your session token
        String bearerToken = String.format("Bearer %s", "YOUR.SESSION.TOKEN");


        JSONObject payload = new JSONObject();
        // add the id of the client-key to deactivated
        payload.put("id", "CLIENT_KEY_ID");



        String endpoint = "https://api.photoilike.com/v2.0/client-key";

        // build the request
        HttpURLConnection connection = (HttpURLConnection) new URL(endpoint).openConnection();
        connection.setRequestMethod("PUT");
        connection.setRequestProperty("Authorization", bearerToken);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);

        OutputStream os = connection.getOutputStream();
        byte[] input = payload.toString().getBytes(StandardCharsets.UTF_8);
        os.write(input, 0, input.length);

        // make the request
        BufferedReader br = new BufferedReader(
                new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)
        );
        StringBuilder response = new StringBuilder();

        for (String responseLine = null; (responseLine = br.readLine()) != null; response.append(responseLine.trim()))
            ;

        // Response in json format
        JSONObject json = new JSONObject(response.toString());
    }

}
<?php

  // Add your token session
  $headers = array(
    'Content-Type:application/json',
    'Authorization: Bearer YOUR.SESSION.TOKEN'
  );

  // Add the id of the client-key to desactivated
  $payload = json_encode(array(
    'id' => 'CLIENT_KEY_ID'
  ));

  $endpoint = "https://api.photoilike.com/v2.0/client-key";

  $ch = curl_init($endpoint);
  curl_setopt($ch,  CURLOPT_POSTFIELDS, $payload);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

  // Make the request
  $result = curl_exec($ch);

  curl_close($ch);

  // Response in json format
  $response = json_decode($result);
 ?>

Obtaining client-keys

Request

GET https://api.photoilike.com/v2.0/client-key

Headers

Fields

Key Value
Authorization string
Required
Session token preceded by the word Bearer.

Request parameters

Fields

Key Value
page int
Optional
Number of the page from which the client-keys are to be obtained. If not specified the default value is 0.

Response to the request

On success, the HTTP status code in the response header is 200 OK and the response body contains an array of client-keys.

Representation

[
    {
        "id": string,
        "activated": bool,
        "name": string,
        "email": string,
        "timestamp": timestamp,
        "apiKeyPrefix": string,
    },
    ...
]

Fields

Parameter Information
id string
Identifier with which PhotoILike stores the client-key information.
activated bool
Indicates whether the client-key is enabled for use or not.
name string
Customer name used in the request.
email string
Customer's email used in the request.
timestamp timestamp
Time instant at which the client-key was generated.
apiKeyPrefix string
The first characters of the client-key token.

This request also uses the headers to add more information in the response.

Key Value
x-total-count string
Total number of client-keys.
link string
It contains a comma-separated list of <link> elements as follows:
<uri_reference>; rel="value", <uri_reference>; rel="value"
The possible values in the rel field are: next, prev, first y last.

Example of a request

curl --request GET \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {YOUR.SESSION.TOKEN}" \
https://api.photoilike.com/v2.0/client-key?page={NUM_PAGE}
import requests

header = {
    # Add your token session
    'Authorization': 'Bearer YOUR.SESSION.TOKEN'
}

params = {
    # Add the num page to retrieve it
    "page": 1
}

endpoint = 'https://api.photoilike.com/v2.0/client-key'

# Make the request
r = requests.get(endpoint, headers=header, params=params)

# Response in json format
response = r.json()
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.json.JSONArray;
import org.json.JSONObject;

public class ClientKey {

    public static void main(String []args) throws Exception {
        // add your session token
        String bearerToken = String.format("Bearer %s", "YOUR.SESSION.TOKEN");

        // add the num page to retrieve it
        int page = 1;

        String endpoint = "https://api.photoilike.com/v2.0/client-key?page=" + page;

        // build the request
        HttpURLConnection connection = (HttpURLConnection) new URL(endpoint).openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Authorization", bearerToken);

        // make the request
        BufferedReader br = new BufferedReader(
                new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)
        );
        StringBuilder response = new StringBuilder();

        for (String responseLine = null; (responseLine = br.readLine()) != null; response.append(responseLine.trim()))
            ;

        // Response in json format
        JSONArray json = new JSONArray(response.toString());
    }

}
<?php

  // Add your token session
  $headers = array(
    'Content-Type:application/json',
    'Authorization: Bearer YOUR.SESSION.TOKEN'
  );


  $endpoint = "https://api.photoilike.com/v2.0/client-key";
  // Add the num page to retrieve it
  $endpoint = $endpoint . "?page=1";

  $ch = curl_init($endpoint);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  // Make the request
  $result = curl_exec($ch);

  curl_close($ch);

  // Response in json format
  $response = json_decode($result);
 ?>