printdotio / printio-api

Issues + wiki for the api. See http://print.io/api
0 stars 0 forks source link

Webhook Set up but returning empty data #35

Closed djeet closed 9 years ago

djeet commented 9 years ago

I have set up webhook https://slack-files.com/T03EW76TW-F08PQ07H6-15724fbe2b

And configured URL : http://dev.myyearstream.com/jsonFromOrders.php

As the state is changed the Webhook works and generates a file at my end. But it returns no data https://slack-files.com/T03EW76TW-F08PQ48BD-0917a8b8cc

Can you check why API is not POSTing anything to URL set.

micahasmith commented 9 years ago

You received a response of [] from the webhook POST?

djeet commented 9 years ago

<?php $time=time(); file_put_contents("$time.txt",json_encode($_POST));
here is the PHP code i am using.

den1k commented 9 years ago

@djeet I assume empty responses ([ ]) are actually GET's that happen when I or anyone clicks your endpoint (http://dev.myyearstream.com/jsonFromOrders.php) in the browser.
Did this ever happen when we posted to your url with a query string containing the orderId, like
http://dev.myyearstream.com/jsonFromOrders.php?orderId=31231283092183 ?

djeet commented 9 years ago

Yes, This happens when i manually change the order status. https://wisetr.slack.com/files/sandeepsoni/F08PQ07H6/pasted_image_at_2015_08_07_07_41_pm.png @den1k This is the way i have set up webhook in the console.

What i am doing wrong?

den1k commented 9 years ago

@djeet Sorry, I can't log into your team's slack. Can you show a case where this happens with query params in the url?

djeet commented 9 years ago

Sorry, i have pasted private url. Here's the public image. Please check. https://slack-files.com/T03EW76TW-F08PQ07H6-15724fbe2b

den1k commented 9 years ago

@djeet This seems correct and I verified that your webhook-url matches the entry in our database. Can you check in your logs of incoming requests, whether the url had query params on it. If it does we know it came from our API, if not the empty body was caused by something else.

djeet commented 9 years ago

@den1k I have checked my server's request logs, found numbers of requests coming from PrintIO end. But i saw the url from which these request is coming is not the way described in webhook reference doc. We are getting the request like /jsonFromOrders.php/orderid=8403-8bb09f61-c006-46e1-b596-a1b78e10dd79 . As you can see orderid here is not a query param. Though it is hitting the correct URL but we are not getting any POST data. Here is the screenshot of my server logs: https://screencloud.net/v/45ly

Here is the log file : https://slack-files.com/T03EW76TW-F08S2RYU8-b407dee0d3

den1k commented 9 years ago

Thank you Djeet. Well the order id is interpolated as a query param, there is just no question-mark in your url, which currently is "http://dev.myyearstream.com/jsonFromOrders.php". Based on your description from last week I extended the validations of our webhook service to also check that the string it posts is not empty. I would say it is now virtually impossible for it to post an empty body. Here's what we posted for one of the URLs in your log screenshot:

2015-Aug-10 08:37:50 +0000 pio-webhook-liv
{:opts
 {:timeout 60000,
  :headers {"Content-Type" "application/json"},
  :body
  "{\"Id\":\"8403-2af4e347-3cdf-4303-8512-c1deff58fe1d\",\"NiceId\":\"soni8403-\",\"SourceId\":\"1\",\"Items\":[{\"Sku\":\"ProPrint-Gloss-5x7\",\"ProductId\":37,\"Product\":\"Professional Prints\",\"Quantity\":2,\"Status\":\"Cancelled\",\"Price\":{\"Price\":1.32,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$1.32\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"DiscountAmount\":{\"Price\":0.00,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$0.00\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"Meta\":{},\"Shipments\":[]},{\"Sku\":\"ProPrint-Gloss-8x10\",\"ProductId\":37,\"Product\":\"Professional Prints\",\"Quantity\":1,\"Status\":\"New\",\"Price\":{\"Price\":1.40,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$1.40\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"DiscountAmount\":{\"Price\":0.00,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$0.00\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"Meta\":{},\"Shipments\":[]},{\"Sku\":\"ProPrint-Gloss-5x7\",\"ProductId\":37,\"Product\":\"Professional Prints\",\"Quantity\":1,\"Status\":\"Cancelled\",\"Price\":{\"Price\":0.66,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$0.66\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"DiscountAmount\":{\"Price\":0.00,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$0.00\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"Meta\":{},\"Shipments\":[]}],\"ShippingTotal\":{\"Price\":9.24,\"CurrencyCode\":\"USD\",\"FormattedPrice\":\"$9.24\",\"CurrencyFormat\":\"${1}\",\"CurrencyDigits\":2},\"ShippingAddress\":{\"FirstName\":\"sandeep\",\"LastName\":\"soni\",\"Line1\":\"c-1/23\",\"Line2\":\"utm\",\"City\":\"new york\",\"State\":\"NY\",\"CountryCode\":\"US\",\"PostalCode\":\"60120\",\"Phone\":\"789845987812\",\"Email\":\"sandeepsoni214@gmail.com\"},\"BillingAddress\":{\"FirstName\":\" \",\"LastName\":\" \",\"Line1\":\" \",\"City\":\" \",\"State\":\" \",\"CountryCode\":\"US\",\"PostalCode\":\" \"}}",
  :method :post,
  :url
  "http://dev.myyearstream.com/jsonFromOrders.php/orderid=8403-2af4e347-3cdf-4303-8512-c1deff58fe1d"

Looking at the logs and considering the fact that other partners have not reported such an issue, I'm tempted to believe that the cause of this issue does not lie on our end.

If you want to do more testing and make sure to know whether and what we posted to you, feel free to ping me here or via email with the url string.

As a note, we received a response for our post which had an empty string in it's body. Could this be what you're seeing?

Hope this helps.

djeet commented 9 years ago

@den1k Thanks for the response. Though we are getting nothing in global $_POST and $_GET. I tried php://input to read the JSON data you're sending. It worked well, i have got the data i wanted, Thanks again. Here is the script i have used- $webhookContent = ""; $webhook = fopen('php://input' , 'rb'); while (!feof($webhook)) { $webhookContent .= fread($webhook, 4096); } fclose($webhook); file_put_contents("$time.txt",$webhookContent); . I am closing this issue.

den1k commented 9 years ago

@djeet Glad it works. Thanks!