this is my first post here. I hope that I get my question right. I use the google translator from German to English because my English is not that good.
I would like to use the "api" from easybill. GET worked. But unfortunately I can't do it with the POST.
I hope someone can help me.
I would like to create a new customer for testing. My goal is to generate invoices later using PHP. The "api" for easybill can be found here: https://www.easybill.de/api/
I tried the following code but unfortunately I can't find the error.
$url = "https://api.easybill.de/rest/v1/customers";
$data = array(
'first_name' => 'Foo',
'last_name' => 'Bar',
'company_name' => 'FooBar GmbH',
'emails' => array ('[email protected]'
)
);
$postdata = json_encode(array($data));
$accesstoken = "XXXXXXXXXXX";
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer '.$accesstoken;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
$result = curl_exec($ch);
curl_close($ch);
print_r ($result);
Best regards from Germany.
Your mistakes:
Content-length: 0
doesn't make any sense and is utterly wrong here. Afaik you can remove it completely since curl does this for you.
$postdata = json_encode(array($data));
will wrap your array in another array, which isn't correct here. It yields in:
[{"first_name":"Foo","last_name":"Bar","company_name":"FooBar GmbH","emails":["[email protected]"]}]
where it has to be:
{"first_name":"Foo","last_name":"Bar","company_name":"FooBar GmbH","emails":["[email protected]"]}
just remove the array call:
$postdata = json_encode($data);
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.