x

Problems with API

Hello,

I'm working to make a website for our staff to use, that has some information about the products in our store. Example could be a list of the costumers who has bought a certain product.

This should be possible through the Store/Order API and example:

curl https://api.weeblycloud.com/user/USER_ID/site/SITE_ID/store/order/ORDER_ID/item \
-H "X-Public-Key: YOURAPIKEY" \
-H "X-Signed-Request-Hash: YOURSECRETHASH"

For a test i tried to do the guide on https://cloud-developer.weebly.com/about-the-rest-apis.html and insertet the data to my site:

<?php
  echo "hello";

  require_once("src/init.php");

?>

<?php
echo "Forsøg";

$sideid = "961961237632906202";
$brugerid ="117649224";
$base_api = "https://api.weeblycloud.com/";
$api_key = "XXXXXXXX/censored";
$api_secret = "XXXXXXXX/censored";

$request_type = "POST";
$url = "user/117649224/site";
$data = array(
"domain" => "fifopizza.dk"
);

$content = json_encode($data);
$hash = hash_hmac('SHA256', $request_type . "\n" . $url . "\n" . $content, $api_secret);
$hash = base64_encode($hash);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_api.$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_type);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'X-Public-Key: ' . $api_key,
'X-Signed-Request-Hash: ' . $hash
));

$out = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

$result = json_decode($out);
if ($info['http_code'] === 200) {
echo "hej med dig";
} else {
echo "fejl";
}
?>

My question is:
How do I rewrite the above code to get, lets say the product id? I know the code is:

curl https://api.weeblycloud.com/user/USER_ID/site/SITE_ID/store/product \
 -H "X-Public-Key: YOURAPIKEY" \
 -H "X-Signed-Request-Hash: YOURSECRETHASH"

But where do i insert this in the above code? I think it has something to do with the variable $url and $request_type that should sat GET and then i should delete the $content variable from the hash string, but i can't workout how.. I simply just want it to post the product id.

Test site:
https://test.joachimschubert.dk/

Best regards

Joachim

1,548 Views
Message 1 of 5
Report
4 REPLIES 4

Hey @JSchubert

First, I would recommend using the Weebly Cloud PHP Client in your application if you aren't already. It is an open-source library that provides a reusable and improvable solution for interacting with our Cloud APIs.

Currently it does not include functionality for accessing "Products" or "Store", but I have spent time today creating the following Pull Request: https://github.com/Weebly/cloud-client-php/pull/7. I would like to see if you could fetch that PR, test it, and respond in the comments of the PR with your review please.

I have included documentation which shows how this should operate to answer your question here, and please do not hesitate to let me know if you have any questions, or if I missed anything please. Smiley Happy

Tags (3)
1,522 Views
Message 2 of 5
Report

Any update if you were able to get this resolved, or need more assistance please @JSchubert?

1,455 Views
Message 3 of 5
Report

I wrote to your support, and got some files that had no relation to the "Weebly Cloud PHP Client" - but I managed to get it to work Smiley Happy
1,403 Views
Message 4 of 5
Report

Glad to hear you got things working again!

1,368 Views
Message 5 of 5
Report