How to create a custom API

hi , im new to cscart , and honestly there’s not even enough documentation on how the api , works, all I have got is the basic template example , I cant create a custom Api , without having functions like create update in my file , I cant even have my own function name , I cant run some basic debug php method like dd(), please I need help , on how to create a custom endpoint , even as basic as just querying my database , any suggestion or help is welcomed , thanks in advance.

Hello,

The fastest way for me to learn was to check how other add-ons are doing it :smiley:

You will need to create your own entities.

ex: please check file

app/addons/call_requests/Tygh/Api/Entities/CallRequests.php

Official Documentation: https://docs.cs-cart.com/latest/developer_guide/api/index.html

I hope this helps

Hi!

Please check this one article:
https://docs.cs-cart.com/latest/developer_guide/addons/api_extending.html

also any idea in how they handle images , fetching api endpoint with images

@hungryweb thanks for the help , yes I figured I will have to create my own entities , but there’s still a lot I need to learn , like for example why cant I have my own function name apart from index , also why do I have to have create , update and delete always present in my controller , and is there a better way of communicating to the database beside Sql like laravel has eloquent , I don’t know if you get me

Have you checked the article I’ve previously sent you? It already contains answers on several of your questions.

For images, you can check the Products entity (app/Tygh/Api/Entities/Products.php). And we have an example how to upload images via API:
https://docs.cs-cart.com/latest/developer_guide/api/entities/products.html#example-json-update-a-product-image

yes this only has the basic layout for an extending api

let me look into this , and get back to you, thanks

@CS-Cart_team , here’s what have noticed , I have tried drafting a create function that stores my banner promotions , but I cant seem to pass the validation , like the name field comes through , but my image does not , also if you can specify how I can do this and store images locally , with like a url so I can use my index request to fetch them , that would be great , please any ideas are accepted , thanks waiting for your response .

Sorry, I didn’t understand. Could you please explain it in more detail?

Please check how images are uploaded in the \Tygh\Api\Entities\Products entity (app/Tygh/Api/Entities/Products.php). Both Products::create and Products::update methods call the Products::prepareImages method, that prepares the URLs passed in the request’s main_pair and image_pairs parameters, to be uploaded into the products.

I hope it will help you.