POST /external/tokens
from your backend using your API key. The body of the request must include the external_user_id
, which represents a unique identifier of your user (e.g. the user's email). Return the token
to your frontend to embed in the iFrame widgets. Here are examples for Python and C#:
class PhotoPacksTokensView(APIView):
def get(self, request, *args, **kwargs):
try:
response = requests.post(
"https://www.photopacks.ai/external/tokens",
headers={
"X-API-Key": os.environ["PHOTO_PACKS_PARTNER_API_KEY"],
"Content-Type": "application/json"
},
json={"external_user_id": request.user.id}
)
response.raise_for_status()
return Response({"token": response.json().get("token")}, status=status.HTTP_201_CREATED)
except requests.exceptions.RequestException as e:
print("Error:", e)
return Response({"error": "Something bad!"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
public class PhotoPacksTokensController : ApiController
{
// Assuming you've stored your API key in the Web.config for example
private static readonly string apiKey = System.Configuration.ConfigurationManager.AppSettings["PhotoPacksPartnerApiKey"];
[HttpGet]
public async Task<IHttpActionResult> GetToken()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://www.photopacks.ai/external/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var payload = new
{
// This should be the unique identifier (e.g. email) of the user that is currently logged-in
external_user_id = User.Identity.Name
};
HttpResponseMessage response = await client.PostAsJsonAsync("tokens", payload);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<dynamic>(content);
return Created(new Uri(Request.RequestUri, "token"), new { token = result.token });
}
return InternalServerError();
}
}
}
token
that you previously retrieved into the iFrame:
<iframe
src={`https://www.photopacks.ai/partners/orders?token=${token}`}
width="100%"
height="600"
frameBorder="0"
>
Sorry, your browser does not support inline frames.
</iframe>
token
. From your backend, call the POST /external/orders
API with your API key and external_user_id
, which represents a unique identifier of your user (e.g. the user's email). Here is an example in Python and C#:
class PhotoPacksOrdersView(APIView):
def post(self, request, *args, **kwargs):
try:
response = requests.post(
"https://www.photopacks.ai/external/orders",
headers={
"X-API-Key": os.environ["PHOTO_PACKS_PARTNER_API_KEY"],
"Content-Type": "application/json"
},
json={"external_user_id": request.user.id}
)
response.raise_for_status()
data = response.json()
return Response(
{"order_id": data.get("order_id")},
status=status.HTTP_200_OK
)
except requests.exceptions.RequestException as e:
print("Error:", e)
return Response({"error": "Something bad!"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
public class PhotoPacksOrdersController : ApiController
{
private static readonly string apiKey = System.Configuration.ConfigurationManager.AppSettings["PhotoPacksPartnerApiKey"];
[HttpPost]
public async Task<IHttpActionResult> CreateOrder()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://www.photopacks.ai/external/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var payload = new
{
// This should be the unique identifier (e.g. email) of the user that is currently logged-in
external_user_id = User.Identity.Name
};
HttpResponseMessage response = await client.PostAsJsonAsync("orders", payload);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<dynamic>(content);
return Ok(new { order_id = result.order_id });
}
return InternalServerError();
}
}
}
order_id
Return the order_id
to your frontend. Pass both the order_id
and token
as parameters into this iFrame to display the Order Creation widget:
<iframe
src={`https://www.photopacks.ai/partners/select-type?id=${orderId}&wizard=true&token=${token}`}
width="100%"
height="600"
frameBorder="0"
>
Sorry, your browser does not support inline frames.
</iframe>
Colors in your widgets can be customized by providing the proper query parameters in the url of the iFrame with a hex value for the color. For example: https://www.photopacks.ai/partners/orders?token=1234&color-700=4701FD
.
The following color query parameters can be provided:
Each of the values represents a particular color in the application (e.g. primary, secondary, tertiary, and buttons states such as hover and enabled).
POST https://www.photopacks.ai/external/tokens
X-API-Key
: Your secret API key
{
"external_user_id": "unique-user-id" # This should come from your user's session
}
{
"token": "your-unique-token" # Inject this into your iFrame
}
POST https://www.photopacks.ai/external/orders
X-API-Key
: Your secret API key
{
"external_user_id": "unique-user-id" # This should come from your user's server-side session
}
{
"order_id": "unique-order-id" # Inject this into your iFrame
}