1

This may be a very basic question, as I am fairly new to php programming. Hopefully I can learn something about my particular issue.

I am trying to build a simple web application with php that will interface with the BBYOpen API provided by Best Buy. The application need to be able to accept a zipcode and distance radius in order to retrieve Best Buy store locations within the parameters.

Now BBYOpen provides queries for developers, which I have managed to find the one I would need to use.

My problem, being new to php, is:

  1. How exactly can I build a simple HTML page that will accept user input (in the form of a zipcode and distance) and tie that into a php script that can communicate with BBYOpen to retrieve the data.

  2. BBYOpen provides extensive documentation for querying and the information that I can feasible return, but I am lost on how to get my php script to connect to BBYOpen. I know that in order to connect I need to utilize their Remix web service, but I am also at a loss at how I would go about doing that.

Any help or solutions would be appreciated, even in a generic code with comments.

Cheers

3
  • Use curl or curl wrappers like Guzzle Commented Apr 21, 2014 at 12:11
  • 1
    Your question is too broad. I have the impression that you first need to learn about HTML forms and basic interaction between browser and server. When you've gatherer the skills to build e.g. a Fahrenheit/Celsius converter, you can concentrate on the API. Commented Apr 21, 2014 at 12:19
  • Alvaro, I have the basic understanding of creating a <Form> that will allow user input such as zipcodes. My issue is how exactly I would take that input and bringing it over to a php script so that it would be placed into the proper place in the query. Commented Apr 21, 2014 at 13:42

1 Answer 1

1
    $ch = curl_init('http://api.remix.bestbuy.com/v1/products?apiKey=apiKey&format=json');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',)
    );

    $result = curl_exec($ch);
    $header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
    $header = substr($result, 0, $header_size);
    $body = substr( $result, $header_size );
    curl_close($ch);

    echo "<pre>";
    print_r(json_decode($body));

end wtih this you can get the data;

$json = file_get_contents('php://input');
$data = json_decode($json, true);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Burhan. To clarify, that is the script that would be placed in the php tags, correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.