Well, Mohamad, to answer that question, I would have to ask a question.
How secure does this system need to be. I will explain a little. If you have a webpage, which you are calling an API, it can be found by hackers or just regular people. If the page pulls data from a database, anyone who finds that page can enter the code by just going to the page.
http://localhost:1367/rest-api2/api-alis.php?material_code=1234;
And, that data would display on the page. So, it can be hacked. They could get all of your data for every material_code by just changing the material_code number. But, if this is handled just locally on your own machines, it is not an issue.
Also, you acquire the number from this:
$material_code = $_GET[‘material_code’];
So, the data returned from the page is NOT protected from hackers. It can include a command that will erase your entire database. You need to at least filter the input like this:
$material_code = filter_input(INPUT_GET, "material_code"];
This will remove any programming that is inside the GET results…
Now, to pass the data directly, you can not use the $_SESSION array if the data is pulled from another page since the other page may not be on the same server. Do you understand that difference.
Therefore, to really answer your question, I need to know how you plan to use this API system. Are you planning on creating the API on a website and then call it from other computers to allow to view the data elsewhere such as on a phone or iPad or other remote computer? If so, you need to do it that way, you can force the connection to log in. Since you use cURL, you can have that log into the api page. Fairly easy. But, adds more work.
If the system is just local, meaning if it is on a server you or your company will be using and no outside people can access it, then security is not important. At the beginning of this post, you mentioned the API part and second part, but, you did not mention how they will link together. Please explain how you will use these two program you showed us and then we can suggest the best way to handle this one.