Development discussions around Shopify APIs
Hello,
I'm creating an internal application that connects to Shopify's API. I'm using PHP, Guzzle and the fulfillment endpoint and I'm getting a 200 code back through Guzzle, but I don't see a fulfillment getting created. I would like to check the body of the response that I get back from Shopify, but I just get redirected to a shopify login. Here is my code:
$client = new GuzzleHttp\Client(['base_uri' => 'https://*:*@*.myshopify.com/']);
$GetOrder = "{
'fulfillment': {
'tracking_number': ".$dbOrder['tracking_number'].",
'line_items': [
{
'id': ".$line_item['id'].",
'quantity': ".$dbOrder['qty_shipped']."
}
]
}
}";
$post_fulfillment = $client->request('POST', 'admin/orders/#'.$dbOrder['order_id'].'/fulfillments.json', ['json' => $GetOrder]);
echo $post_fulfillment->getBody()->getContents();
When I run this function I get redirected to a shopify login page. I'm thinking something is wrong with my $GetOrder structure because there is no fulfillment getting created on the order, but I'm not sure since I can't see the response!
Hey Eric,
In these cases, a redirect to the Shopify login page is a result of your request not being authenticated. Your app cannot read Shopify data without authenticating first. I noticed that your code doesn't include API credentials, so this could very well be the reason for the redirect.
Here is a doc describing how to quickly generate API credentials so you can authenticate with your Shopify store.
- Jordan
Jordan | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hey Jordan,
I definitely have the credentials set up as I am able to access all of my test orders through the orders endpoint. You will see on the first line of code my base shopify URI:
$client = new GuzzleHttp\Client(['base_uri' => 'https://*:*@*.myshopify.com/']);
I replaced my information with * for obvious reasons. Is there anything else that could be the issue?
I did some further testing. I copy/pasted my API URL to get test orders in my browser and I got a JSON response of all my test orders. I copy/pasted my API URL to get test customers in my browser and I got a JSON response of all my test customers.
I manually fulfilled a test order in Shopify and copy/pasted the API URL to get all the fulfillments for an order, and I got redirected to the orders page in Shopify.
This is the URL I used to try to grab the fulfillment for my manually fulfilled order:
https://*:*@sppjd.myshopify.com/admin/orders/#1003/fulfillments.json - This redirected me to my shopify orders page
https://*:*@sppjd.myshopify.com/admin/orders/1003/fulfillments.json - This gave me a 404 not found response
I feel like I'm missing something small here. My store is currently password protected if that matters
Oops found the issue.. Was trying to use the order number and not the order id. Using the order id fixed it
I am still having issues 😞 Now I'm getting a 400 bad request error when trying to create the fulfillment.
Here is my updated code:
$client = new GuzzleHttp\Client(['base_uri' => 'https://****:****@sppjd.myshopify.com/']);
$arguments = array(
"fulfillment" => array(
"tracking_number" => "0000",
"notify_customer" => false
)
);
$post_fulfillment = $client->post('admin/orders/3115277959/fulfillments.json');
$post_fulfillment->addHeader('Content-Type', 'application/json');
$post_fulfillment->addHeader('Accept', 'application/json');
$post_fulfillment->setBody(json_encode($arguments));
$post_response = $post_fulfillment->send()->json();
I am getting this error:
400 Bad Request` response: {"errors":{"fulfillment":"Required parameter missing or invalid"}}
My json request looks ok..:
{"fulfillment":{"tracking_number":"0000","notify_customer":false}}
I've went through tons of topics and most everyone's issue with this error was they didn't have a content-type header, but as you can see I am putting it in there.
I'm using Guzzle 6, please someone help!
Hey Eric,
Glad to hear you sorted out the previous issue with the correct order ID!
As for this new issue, it seems the formatting of your json is a little off. From our logs, the json in your request is formatted like this:
{"_json"=>"{\"fulfillment\":{\"tracking_number\":\"***\",\"notify_customer\":false,\"line_items\":[{\"id\":***}]}}"
when it should be:
{"fulfillment"=>{"tracking_number"=>"***", "notify_customer"=>false, "line_items"=>[{"id"=>***}]}
I hope this points you in the right direction!
- Jordan
Jordan | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thank you Jordan, got it to work with that
Hi Jordan!
I am having an issue on creating a new customer using Shopify API.
I set the api key and password to url, response is 200 but response body is login page!
User | RANK |
---|---|
10 | |
4 | |
3 | |
3 | |
3 |
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023