Does your server have cURL installed? It’s your best choice since the API examples use it. Use this basic example as guidance for setting up and terminating cURL via PHP.
You could put the form HTML and code to handle form submittal and API request all on a custom page template.
The API example uses the command line version of cURL, you need to use PHP functions. To send the auth headers, do somehing like
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer api_key'
'Content-Type: application/json'
'Accept: application/json'
'User-Agent: My test client'
));
To get the JSON data returned by cURL into a PHP array for further processing, use json_decode()
Thread Starter
ProWeb
(@prowebids)
Have requested that the webbhotell installs the cURL on my account.
i am really greatfull for the help, sorry about my spelling but english isnt my first langue.
this is the first time a work with API so i am totaly lost :/
ok when i get the cURL to work where should i put the code to make it work, what file i mean.
thanks in advance
/prowebids
There are a few possible approaches. What I’d do is create a custom page template and include the code as the portion that handles form submittals. This way the form page can submit to itself. The template code can conditionally decide what to do based on the request type (GET or POST), or by the presence or lack of a certain value in $_REQUEST.
To avoid having your custom template be lost during a theme update, it’s recommended that you create a child theme to contain all of your custom work.