DEV Community

leves96
leves96

Posted on

How can I write it out? B2B API

Hi, im a simple user and i got a b2b api key with some sample code. I want to list all the products from a company. First to my localhost. Maybe later to my website.. (not webshop)

The Sample Code:

https://api.thisisthesite.com,
POST: {
"apikey": "ihavethekey",
"method": "GetProductsList",
"parameters": [
{
"ShowGroups": "1",
"ShowIndex": "1"
}
]
}

I want to write out: GetProductInfo ; GetProductList ; GetProductsWarranty.

How can i get these? thank you for helping. I have wampserver, js.node and sublime text.

Top comments (2)

Collapse
 
nlxdodge profile image
NLxDoDge

Hi welcome to Dev.to, first some nice tips to make your code snippet look a little but better.

{
    "apikey": "ihavethekey",
    "method": "GetProductsList",
    "parameters": [
        {
            "ShowGroups": "1",
            "ShowIndex": "1"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

With the triple backtick around your code on top and bottom you can make the formatting a little nicer.

Second, you didn't specify if you want to call this from PHP (the backend) or from Javascript (front-end) so I just assumed you where going to use the backend for this.

Here is a small snippet to get you up to speed in PHP, there are of course lots of libraries to do this better but cURL is your best friend here:

<?php

function httpPost($url, $data)
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

$options = [
    'apikey' => 'INSERT_API_KEY_HERE',
    'method': 'GetProductsList',
    'parameters': [
        'ShowGroups': '1',
        'howIndex': '1'
    ]
];

echo(httpPost("https://website.com/endpoint", $options));
?>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leves96 profile image
leves96

thank you for your answer, so i see but the endpoint is my localhost. and the product list is from an another website. i tried it but doesnt work

From: api.wycena.keno-energy.com/
To: my localhost
API: IHAVETHEKEY

API DOCU: api.wycena.keno-energy.com/Dokumen...