Step 6: Make Your First API Call

With your API key integrated, you are ready to make your first request to the Imagior API. This initial call will help you verify that your integration is working correctly and allow you to start generating or managing images.

Important Requirements Before Your First Call

  1. Template ID: Make sure you have the ID of the design template you created earlier. This ID is required to specify which design template you want to use for generating images.
  2. Credits: Ensure your account has at least 1 credit available, as generating an image will cost 1 credit per image.
  3. Body Parameter: The body of your request can be used to dynamically modify elements in your design template. If you provide a body, you can change text, colors, images, or other elements defined in the template. If you do not provide a body, the image will be generated using the default settings of the template without any changes.

How to Make Your First API Call

Prepare Your Environment

You can use tools like Postman, cURL, or any programming language that supports HTTP requests.

Construct Your API Request

Create a request to the Imagior API using the desired endpoint. Make sure to include your API key in the Authorization header.

Example of a Simple API Call

Here’s a simple example to help you get started with your first API call. This request sends a POST request to the Imagior API to generate an image using a specific design template.

Example using cURL

curl -X POST https://api.imagior.com/image/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"templateId": "YOUR_TEMPLATE_ID",
"elements": {
"text": "New Text",
"color": "#FF5733"
}
}'
  • Replace YOUR_API_KEY with the actual API key you copied from the Developers page.
  • Replace YOUR_TEMPLATE_ID with the ID of the design template you created.

Understanding the Request Body

  • templateId: The unique ID of the design template you created earlier. This is mandatory for the API to know which template to use.
  • modifications: An optional object that specifies any changes you want to apply to the template, such as new text, colors, or images. If you do not provide this object, the API will generate the image using the default settings of the template without any modifications.

Code Examples in Various Languages

Use the examples below to see how you can make an API call using different programming languages:

Understanding the Response

A successful API call will return a JSON response with details about the generated image, credit usage, and other metadata. Here is a sample of what the response might look like:

{
   "status": "success",
   "statusCode": 200,
   "message": "Image generated and credits updated",
   "imageURL": "https://cdn.imagior.com/images/sample-image.png",
   "details": {
      "dimensions": {
         "width": 1080,
         "height": 1080
      },
      "format": "png"
   },
   "usage": {
      "previousCredits": 10,
      "creditsUsed": 1,
      "remainingCredits": 9
   },
   "requestCompletionTime": "4632 ms",
   "timestamp": "2024-09-12T02:44:45.213Z"
}
  • status: Indicates whether the request was successful or not.
  • imageURL: A URL to the generated image.
  • usage: Details the credits used for this request and the remaining credits in your account.
  • requestCompletionTime: The time it took to complete the request.
  • timestamp: The date and time when the request was completed.

Verify Your API Call

  1. Check the Response: If your request is successful, you should receive a response similar to the one above. This confirms that your integration is working correctly.
  2. Handle Errors: If the request fails, check the response for error messages. Common issues might include an invalid API key, insufficient credits, incorrect endpoint, or missing template ID.

Tips for Your First API Call

  • Ensure You Have Credits: Remember, each image generated costs 1 credit. Make sure your account has enough credits to perform the operation.
  • Include the Template ID: Always specify the template ID for the image you want to generate or modify.
  • Use Modifications Wisely: Use the body parameter to dynamically change elements in your template. If no modifications are passed, the image will be generated with default settings.
  • Use Tools: Tools like Postman or cURL can help you test your API calls and debug any issues before implementing them in your application.
  • Read the API Documentation: Familiarize yourself with the available endpoints and parameters by visiting the API Reference.

Next Steps: Explore the API

Now that you’ve made your first API call, you can start exploring other endpoints and functionalities provided by the Imagior API.

Start with the Generate Image endpoint for more information.

Need Help?
If you encounter any issues or need further guidance, please visit our Support Center.