I am using Shopify API to create products and orders. But I can't find a way to checkout my order through api call.
$request = new CURLCall();
$line_items = array("line_items" =>
array(array(
"variant_id" => 123456789,
"quantity" => 5))
);
$data = json_encode(array("checkout" => $line_items));
$url = "https://{API_KEY}:{Password}#shop.myshopify.com/admin/checkouts.json";
// Initialize CURL for PHP
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
'Accept: application/json')
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
print_r($response);
Code above returns this message,
{"errors":"Not Found"}
Thank you.
First off, you cannot checkout an order with the API. Secondly, you can read the abandoned checkouts with your call to the checkouts endpoint.
If you want to actually cash in an order you create, you would want to create a transaction for the order, not a checkout. You can create capture transactions for example. You can never actually transact money this way though... your customer has to enter their credit card details to turn API created orders into real ones.
Related
I am developing php application for submitting my Employers data into bullhorn using rest api.
I have bullhorn account and client id and client secret
I read documentation and also see question in
[Insert candidate with categories + BullHorn
one of stack overflow but not find any solution
Can any one help me how to use api for php??
Thanks in advance
Below Code I used to Create an company in BullHorn CRM using RESTAPI
Here Use Company as ClientCorporation object.
$url = 'https://rest2.bullhornstaffing.com/rest-services/rggmp/entity/ClientCorporation?BhRestToken=09c4822e-04e7-40d8-9570-addc5c447aa7';
$params =array("name"=> "Maha","fax"=>231312313 );
$post_params = json_encode($params);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST,$method); // for Create -> "PUT" & Update ->"POST" //
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($post_params));
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$response = json_decode($result, true);
print_r($response);
curl_close($curl);
Output :
(
[changedEntityType] => ClientCorporation
[changedEntityId] => 304
[changeType] => INSERT
)
I am trying to Upload the Product to Woo commerce Store but on upload it gives me the below Error code am not sure where am going Wrong.
and I am note Sure on one Case to Should i have to include any Lib to make work if help me on that
FYI: this is a V3 API code of woocommerce
Error Code
{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}
My Code
$aData = array(
'product' => array(
'title' => 'Premium Quality',
'type' => 'simple'
)
);
$sData = json_encode($aData);
$ch = curl_init('http://example.com/demo/ir/wc-api/v3/products');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $sData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'ck_xxxxxxxxxxxxxxxxxx:cs_xxxxxxxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($sData))
);
$result = curl_exec($ch);
print_r($result);
I am using kloon-WooCommerce-REST-API-Client-Library.
I had a similar problem after upgrading to v3. I read through the authentication process in class-wc-api-authentication.php and found the difference was I needed to append an unencoded & to the consumer secret before using it to sign my parameter string.
$secret = $consumer_secret . '&';
I've been stuck trying to update or delete a metafield that i created on user registration via the shopify customer API.
At first i tried to update the metafield using the customer API but it told me that the metafield already existed and i cannot add it again.
Then i used the user ID and made a call to retrieve all the metafields linked to the user using the metafield API - this worked and it returned all the metafields for me.
However my issue starts when i want to either delete or update the metafield that i've created.
I've tried a lot of different variations of REST calls but nothing seems to work.
To try and delete i used:
$baseUrl = "https://".$apikey.":".$password."#".$hostname."/admin/";
......
$curl = curl_init($baseUrl.'metafields/'.$metaID.'.json');
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Make the REST call, returning the result
$response = curl_exec($curl);
var_dump($response);
This did not do anything, so i tried going a level deeper and used the following URL:
$curl = curl_init($baseUrl.'customers/'.$custID.'/metafields/'.$metaID.'.json');
This URL did not work either.
Then I decided that i might as well just try and update the metafield to the new value that it was supposed to have.
I then tried the tried the following to update the value:
$metafield = array('metafields' => array(array(
'id' => $metaID,
'value' => '3',
'value_type' => 'string',
)));
$curl_url = $baseUrl.'customers/'.$custID.'/metafields/'.$metaID.'.json';
$ch = curl_init($curl_url);
$data_string = json_encode(array('metafield'=>$metafield));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
After that i tried the alternative URL:
$curl_url = $baseUrl.'metafields/'.$metaID.'.json';
Any idea where i messed up?
Part 2 works now - creating and updating a metafield
So after writing and testing different sets of code i got something to work.
$data = array('metafield' =>
array(
'key' => 'level',
'value' => '1',
'value_type' => 'string',
'namespace' => 'Wholesaler'
)
);
$curl_url = $baseUrl.'customers/'.$custID.'/metafields.json';
//$ch = curl_init($baseUrl.$sid.'.json'); //set the url
$session = curl_init($curl_url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: POST') );
curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if(ereg("^(https)",$curl_url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($session);
curl_close($session);
$json = json_decode( $response, true );
var_dump($json);
echo "<br>-------------------------------------------------<br>";
echo $curl_url;
This code allowed me to create a metafield for a user that did not have it as well as update that metafield, as long as the key field and namespace makes it unique it will create a new field, if you use a key and namespace that already exists it will update the value.
I hope this helps someone else out there.
I do this call and it works perfect everytime:
DELETE /admin/customers/123456789/metafields/987654321.json
Where my customer ID is 123456789 and the metafield I want to kill has the ID 987654321
Part one is done - Delete
After doing alot of research and trying different pieces of script the following worked for me:
$curl_url = $baseUrl.'customers/'.$custID.'/metafields/'.$metaID.'.json';
//$curl_url = $baseUrl.'metafields/'.$metaID.'.json';
$session = curl_init($curl_url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if(ereg("^(https)",$curl_url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($session);
curl_close($session);
$json = json_decode( $response, true );
var_dump($json);
I can now delete a metafield.
I'm developing a web application for my co-workers, so they'll have an iPad with an application, to package our orders.
Whole app is almost finished, one of the last steps is to change order status from processing to completed.
What I'm doing:
Get current order ID, then change status with curl or API. What happens is very strange, I get JSON data back, and the completed_at time updated, but status is still processing.
Below you will see my code:
$data = array("status" => "completed");
$data_string = json_encode($data);
$username = 'XXX'; // Add your own Consumer Key here
$password = 'XXX'; // Add your own Consumer Secret here
$ch = curl_init('https://www.deallerleukste.nl/wc-api/v2/orders/5764?consumer_key='.$username.'&consumer_secret='.$password);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
echo $result;
Anyone who sees what I'm doing wrong? Please help!
Regards,
Jelmer
Try Using this code
$data='{ "order": { "status": "completed" }}';
or
Dynamically
$data=json_encode( array( 'order' => array( 'status' => $status)));
in $status you can pass the status u want.
I see it is a quite old post, but today I ran into the same problem, so maybe it is useful.
You have to use PUT instead of POST here:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
and data should be a valid JSON in this format:
$data='{"status": "completed"}';
i have a test shop on shopify. When the orders are created I want to update their fulfilment status to "Fulfilled" via PHP API calls.
So far nothing is mentioned in the documentation to update the fulfilment status of the line items in the order.
Is there any way to do so?
Yes. API Fulfillment is possible: http://api.shopify.com/fulfillment.html
This is how I have it working now
$data = array( "fulfillment" => array("tracking_number" => "1111111111"));
$data_string = json_encode($data);
$ch = curl_init('https://API:PASS#STORE.myshopify.com/admin/orders/ORDER_ID/fulfillments.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print_r($result);