• Hello all i have struck a wall, i need help with getting an API working on a webbpage url https://proweb.se/demozone/Ecoshine its a dummy site now but i will try explain it, how it should work.

    the setup is WP with WooCommerce and the API should get the information for the carregistration.

    it should work like on this page https://wipers.se/ so you can se it.

    i have tried everything but i cant get it too work.
    i have the instruction for the API here https://apidocs.biluppgifter.se/

    i am greatful for any help! specially where i should have the code/what file and so on.

    thanks in advance
    /prowebids

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    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

    Moderator bcworkz

    (@bcworkz)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘API for an webbshop’ is closed to new replies.