Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottpayne/0341cf085b649c4161319384a170982f to your computer and use it in GitHub Desktop.
Save scottpayne/0341cf085b649c4161319384a170982f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A little setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"require 'faraday'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
":call"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"module FaradayMiddleware\n",
" class JsonBodyParser\n",
" def initialize(app)\n",
" @app = app\n",
" end\n",
"\n",
" def call(request_env)\n",
" if request_env[:request_headers][\"content-type\"] =~ /json/ && request_env[:body]\n",
" request_env[:body] = request_env[:body].to_json\n",
" end\n",
"\n",
" @app.call(request_env).on_complete do |response_env|\n",
" if response_env[:response_headers][\"content-type\"] =~ /json/\n",
" response_env[:body] = JSON.parse(response_env[:body])\n",
" end\n",
" end\n",
" end\n",
" end\n",
"end\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"https://app.gyroapi.com/developers/api/v1\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api_key = \"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\n",
"\"\n",
"gyro_base_url = \"https://app.gyroapi.com/developers/api/v1\""
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"#<Faraday::Connection:0x00007fffd2283de8 @parallel_manager=nil, @headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x00007fffd2283a50 @handlers=[FaradayMiddleware::JsonBodyParser, Faraday::Response::Logger, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1>, @manual_proxy=false, @proxy=nil, @temp_proxy=nil>"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conn = Faraday.new(gyro_base_url, headers: { \"Authorization\" => \"bearer #{api_key}\" }) do |faraday|\n",
" faraday.use FaradayMiddleware::JsonBodyParser\n",
" faraday.response(:logger, nil, bodies: true)\n",
" faraday.adapter Faraday.default_adapter\n",
"end\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First things first, let's check the status"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"frodo-myob-essential\""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"user = 'frodo-myob-essential'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-01T11:20:01.220802 #27665] INFO -- request: GET https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/check\n",
"D, [2018-08-01T11:20:01.221288 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-08-01T11:20:02.133258 #27665] INFO -- response: Status 200\n",
"D, [2018-08-01T11:20:02.134051 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 01:18:54 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"3b5b0e7ff1a0cdaca8318db3878e5a38\\\"\"\n",
"x-runtime: \"0.036143\"\n",
"x-request-id: \"2e23269b-05ce-4c94-a0dc-38bc742cc63d\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-01T11:20:02.135657 #27665] DEBUG -- response: {\"client\"=>\"frodo-myob-essential\",\n",
" \"platform\"=>true,\n",
" \"platform_name\"=>\"Myob Essential\",\n",
" \"client_access\"=>true}\n",
"\n"
]
},
{
"data": {
"text/plain": [
"{\"client\"=>\"frodo-myob-essential\", \"platform\"=>true, \"platform_name\"=>\"Myob Essential\", \"client_access\"=>true}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conn.get(\"#{user}/check\").body"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All set up, no need to authorise."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting the accounts\n",
"\n",
"After all that setup, we can get the contacts for this user."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:10:01.523197 #27665] INFO -- request: GET https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/items\n",
"D, [2018-08-02T09:10:01.523527 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-08-02T09:10:03.027030 #27665] INFO -- response: Status 200\n",
"D, [2018-08-02T09:10:03.027426 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:08:55 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"6dce3e78cf02697a7d7d2ab678e18775\\\"\"\n",
"x-runtime: \"0.575407\"\n",
"x-request-id: \"19db4f55-79cd-4d04-9d16-6fcc0b05851c\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:10:03.028201 #27665] DEBUG -- response: {\"software_type\"=>\"MyobEssential\",\n",
" \"items\"=>\n",
" [{\"item_id\"=>\"5059216\",\n",
" \"name\"=>\"zupply_sales_item\",\n",
" \"description\"=>\"An item sold through Zupply\",\n",
" \"is_active\"=>true,\n",
" \"unit_price\"=>0.0}],\n",
" \"status\"=>200}\n",
"\n"
]
},
{
"data": {
"text/plain": [
"{\"software_type\"=>\"MyobEssential\", \"items\"=>[{\"item_id\"=>\"5059216\", \"name\"=>\"zupply_sales_item\", \"description\"=>\"An item sold through Zupply\", \"is_active\"=>true, \"unit_price\"=>0.0}], \"status\"=>200}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"item_resp = conn.get(\"#{user}/items\").body"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"software_type\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"MyobEssential\"\u001b[0m,\n",
" \"items\"\u001b[0;37m => \u001b[0m[\n",
" \u001b[1;37m[0] \u001b[0m{\n",
" \"item_id\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"5059216\"\u001b[0m,\n",
" \"name\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"zupply_sales_item\"\u001b[0m,\n",
" \"description\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"An item sold through Zupply\"\u001b[0m,\n",
" \"is_active\"\u001b[0;37m => \u001b[0m\u001b[1;32mtrue\u001b[0m,\n",
" \"unit_price\"\u001b[0;37m => \u001b[0m\u001b[1;34m0.0\u001b[0m\n",
" }\n",
" ],\n",
" \"status\"\u001b[0;37m => \u001b[0m200\n",
"}\n"
]
}
],
"source": [
"require 'ap' ; ap item_resp"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Single Contact\n",
"\n",
"Can we get a single contact for the user?"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-07-31T10:37:09.348488 #17611] INFO -- request: GET https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/accounts/41168729\n",
"D, [2018-07-31T10:37:09.348843 #17611] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-07-31T10:37:10.424454 #17611] INFO -- response: Status 200\n",
"D, [2018-07-31T10:37:10.424777 #17611] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Tue, 31 Jul 2018 00:36:03 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"79524f763df360768c111eb58bc3b634\\\"\"\n",
"x-runtime: \"0.488948\"\n",
"x-request-id: \"42a0a17f-e294-49cc-bcbe-9ba6a142a553\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-07-31T10:37:10.425478 #17611] DEBUG -- response: {\"software_type\"=>\"MyobEssential\",\n",
" \"account\"=>\n",
" {\"account_id\"=>\"41168729\",\n",
" \"name\"=>\"Fee income\",\n",
" \"type\"=>\"Income\",\n",
" \"bank_account_number\"=>300,\n",
" \"is_active\"=>true,\n",
" \"description\"=>300,\n",
" \"tax_type\"=>\"Goods & Services Tax\"},\n",
" \"status\"=>200}\n",
"\n",
"{\n",
" \"software_type\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"MyobEssential\"\u001b[0m,\n",
" \"account\"\u001b[0;37m => \u001b[0m{\n",
" \"account_id\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"41168729\"\u001b[0m,\n",
" \"name\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"Fee income\"\u001b[0m,\n",
" \"type\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"Income\"\u001b[0m,\n",
" \"bank_account_number\"\u001b[0;37m => \u001b[0m300,\n",
" \"is_active\"\u001b[0;37m => \u001b[0m\u001b[1;32mtrue\u001b[0m,\n",
" \"description\"\u001b[0;37m => \u001b[0m300,\n",
" \"tax_type\"\u001b[0;37m => \u001b[0m\u001b[0;33m\"Goods & Services Tax\"\u001b[0m\n",
" },\n",
" \"status\"\u001b[0;37m => \u001b[0m200\n",
"}\n"
]
}
],
"source": [
"ap conn.get(\"#{user}/accounts/#{body[\"accounts\"].first[\"account_id\"]}\").body"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Yes! That will make things a lot easier then."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-01T13:21:04.924151 #27665] INFO -- request: POST https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-01T13:21:04.925053 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-08-01T13:21:07.489985 #27665] INFO -- response: Status 200\n",
"D, [2018-08-01T13:21:07.490575 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 03:20:00 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"0df29b91cdfa2a0a413b9f614db6f457\\\"\"\n",
"x-runtime: \"0.752220\"\n",
"x-request-id: \"4600f249-fbfd-488f-bed7-6deae02176c0\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-01T13:21:07.491079 #27665] DEBUG -- response: {\"software_type\"=>\"MyobEssential\", \"invoices\"=>[], \"status\"=>200}\n",
"\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd195bba8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={\"software_type\"=>\"MyobEssential\", \"invoices\"=>[], \"status\"=>200} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\", \"Content-Length\"=>\"0\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd195bba8 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 03:20:00 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"200 OK\", \"cache-control\"=>\"max-age=0, private, must-revalidate\", \"vary\"=>\"Origin\", \"etag\"=>\"W/\\\"0df29b91cdfa2a0a413b9f614db6f457\\\"\", \"x-runtime\"=>\"0.752220\", \"x-request-id\"=>\"4600f249-fbfd-488f-bed7-6deae02176c0\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=200 @reason_phrase=\"OK\">>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conn.post(\"#{user}/invoices\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T08:58:33.232110 #27665] INFO -- request: GET https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-02T08:58:33.233291 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-08-02T08:58:37.858665 #27665] INFO -- response: Status 200\n",
"D, [2018-08-02T08:58:37.859537 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 22:57:30 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"fb258a68aad93c5aec18491856d9c720\\\"\"\n",
"x-runtime: \"1.510821\"\n",
"x-request-id: \"92a7ff49-0be1-444f-8b83-21279a4a0e73\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T08:58:37.862250 #27665] DEBUG -- response: {\"software_type\"=>\"MyobEssential\",\n",
" \"invoices\"=>\n",
" [{\"invoice_uid\"=>\"289156361\",\n",
" \"invoice_number\"=>\"IV00000000001\",\n",
" \"contact_uid\"=>\"21014848\",\n",
" \"contact_name\"=>\"Fried Chicken Liver Lovers\",\n",
" \"issue_date\"=>\"2018-08-01\",\n",
" \"due_date\"=>\"2018-08-31\",\n",
" \"total_amount\"=>23.5,\n",
" \"total_tax\"=>\"\",\n",
" \"amount_paid\"=>\"\",\n",
" \"amount_due\"=>23.5,\n",
" \"status\"=>\"Open\"}],\n",
" \"status\"=>200}\n",
"\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd12ef350 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body={\"software_type\"=>\"MyobEssential\", \"invoices\"=>[{\"invoice_uid\"=>\"289156361\", \"invoice_number\"=>\"IV00000000001\", \"contact_uid\"=>\"21014848\", \"contact_name\"=>\"Fried Chicken Liver Lovers\", \"issue_date\"=>\"2018-08-01\", \"due_date\"=>\"2018-08-31\", \"total_amount\"=>23.5, \"total_tax\"=>\"\", \"amount_paid\"=>\"\", \"amount_due\"=>23.5, \"status\"=>\"Open\"}], \"status\"=>200} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd12ef350 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 22:57:30 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"200 OK\", \"cache-control\"=>\"max-age=0, private, must-revalidate\", \"vary\"=>\"Origin\", \"etag\"=>\"W/\\\"fb258a68aad93c5aec18491856d9c720\\\"\", \"x-runtime\"=>\"1.510821\", \"x-request-id\"=>\"92a7ff49-0be1-444f-8b83-21279a4a0e73\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=200 @reason_phrase=\"OK\">>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"conn.get(\"#{user}/invoices\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"MJ has posted the invoice docs and it makes no mention of line item id. So let's try posting just with the documented data structure."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"false"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"require 'active_support/duration'\n",
"require 'active_support/core_ext/integer'"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:16:32.581686 #27665] INFO -- request: GET https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/contacts\n",
"D, [2018-08-02T09:16:32.582067 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"I, [2018-08-02T09:16:33.903515 #27665] INFO -- response: Status 200\n",
"D, [2018-08-02T09:16:33.905377 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:15:26 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"200 OK\"\n",
"cache-control: \"max-age=0, private, must-revalidate\"\n",
"vary: \"Origin\"\n",
"etag: \"W/\\\"6a515c160dd712d07f3844e24ee9389a\\\"\"\n",
"x-runtime: \"0.521114\"\n",
"x-request-id: \"6ecc25ce-51a2-4e2e-90e7-ef12bbd9f4dc\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:16:33.906843 #27665] DEBUG -- response: {\"software_type\":\"MyobEssential\",\"contacts\":[{\"contact_id\":\"21014848\",\"name\":\"Freddy Fryer\",\"type\":\"\",\"is_active\":true,\"description\":\"\",\"company_name\":\"Fried Chicken Liver Lovers\",\"addresses\":\" \",\"phones\":\"\",\"email\":\"\"},{\"contact_id\":\"21014838\",\"name\":\"Joe Bloggs\",\"type\":\"\",\"is_active\":true,\"description\":\"\",\"company_name\":\"Joe Bloggs\",\"addresses\":\" \",\"phones\":\"\",\"email\":\"myob.zupply.joe.bloggs@scottpayne.com.au\"}],\"status\":200}\n"
]
},
{
"data": {
"text/plain": [
"{\"contact_id\"=>\"21014848\", \"name\"=>\"Freddy Fryer\", \"type\"=>\"\", \"is_active\"=>true, \"description\"=>\"\", \"company_name\"=>\"Fried Chicken Liver Lovers\", \"addresses\"=>\" \", \"phones\"=>\"\", \"email\"=>\"\"}"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contact = conn.get(\"#{user}/contacts\").body[\"contacts\"].first"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\"item_id\"=>\"5059216\", \"name\"=>\"zupply_sales_item\", \"description\"=>\"An item sold through Zupply\", \"is_active\"=>true, \"unit_price\"=>0.0}"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"item = item_resp[\"items\"].find {|item| item[\"name\"] == 'zupply_sales_item'}"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"2018-09-01T23:13:51Z\""
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
" 1.month.from_now.utc.iso8601"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:16:05.472151 #27665] INFO -- request: POST https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-02T09:16:05.472514 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"content-type: \"application/json\"\n",
"D, [2018-08-02T09:16:05.472853 #27665] DEBUG -- request: {\"contact_id\":\"21014848\",\"due_date\":\"2018-09-01T23:16:05Z\",\"issue_date\":\"2018-08-01T23:16:05Z\",\"line_items\":[{\"description\":\"An item sold through Zupply\",\"quantity\":\"1\",\"amount\":\"26.57\"}]}\n",
"I, [2018-08-02T09:16:06.517502 #27665] INFO -- response: Status 400\n",
"D, [2018-08-02T09:16:06.517911 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:14:59 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"400 Bad Request\"\n",
"cache-control: \"no-cache\"\n",
"vary: \"Origin\"\n",
"x-runtime: \"0.465100\"\n",
"x-request-id: \"01a5b54b-d611-4287-afcd-9b75e0efe0aa\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:16:06.518151 #27665] DEBUG -- response: {\"response\":\"MyOB Bad Request\",\"status\":400}\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd24669f8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={\"response\"=>\"MyOB Bad Request\", \"status\"=>400} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\", \"content-type\"=>\"application/json\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd24669f8 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 23:14:59 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"400 Bad Request\", \"cache-control\"=>\"no-cache\", \"vary\"=>\"Origin\", \"x-runtime\"=>\"0.465100\", \"x-request-id\"=>\"01a5b54b-d611-4287-afcd-9b75e0efe0aa\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=400 @reason_phrase=\"Bad Request\">>"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# try as documented\n",
"invoice = {\n",
" \"contact_id\": contact[\"contact_id\"],\n",
" \"due_date\": 1.month.from_now.utc.iso8601,\n",
" \"issue_date\": DateTime.now.utc.iso8601,\n",
" \"line_items\": [\n",
" {\n",
" \"description\": item[\"description\"],\n",
" \"quantity\": \"1\",\n",
" \"amount\": \"26.57\"\n",
" }\n",
" ]\n",
"}\n",
"conn.post(\"#{user}/invoices\", invoice, { 'content-type' => 'application/json' })"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:19:19.212566 #27665] INFO -- request: POST https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-02T09:19:19.212861 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"content-type: \"application/json\"\n",
"D, [2018-08-02T09:19:19.213278 #27665] DEBUG -- request: {\"contact_id\":\"21014848\",\"due_date\":\"2018-09-01T23:19:19Z\",\"issue_date\":\"2018-08-01T23:19:19Z\",\"line_items\":[{\"item_id\":\"5059216\",\"description\":\"An item sold through Zupply\",\"quantity\":\"1\",\"amount\":\"26.57\"}]}\n",
"I, [2018-08-02T09:19:20.250782 #27665] INFO -- response: Status 400\n",
"D, [2018-08-02T09:19:20.251221 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:18:12 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"400 Bad Request\"\n",
"cache-control: \"no-cache\"\n",
"vary: \"Origin\"\n",
"x-runtime: \"0.521655\"\n",
"x-request-id: \"06f04b12-43db-4905-98a0-efbefe1280be\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:19:20.251477 #27665] DEBUG -- response: {\"response\":\"MyOB Bad Request\",\"status\":400}\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd251ccf8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={\"response\"=>\"MyOB Bad Request\", \"status\"=>400} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\", \"content-type\"=>\"application/json\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd251ccf8 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 23:18:12 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"400 Bad Request\", \"cache-control\"=>\"no-cache\", \"vary\"=>\"Origin\", \"x-runtime\"=>\"0.521655\", \"x-request-id\"=>\"06f04b12-43db-4905-98a0-efbefe1280be\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=400 @reason_phrase=\"Bad Request\">>"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# no good - try adding an item id\n",
"invoice = {\n",
" \"contact_id\": contact[\"contact_id\"],\n",
" \"due_date\": 1.month.from_now.utc.iso8601,\n",
" \"issue_date\": DateTime.now.utc.iso8601,\n",
" \"line_items\": [\n",
" {\n",
" \"item_id\": item[\"item_id\"],\n",
" \"description\": item[\"description\"],\n",
" \"quantity\": \"1\",\n",
" \"amount\": \"26.57\"\n",
" }\n",
" ]\n",
"}\n",
"conn.post(\"#{user}/invoices\", invoice, { 'content-type' => 'application/json' })"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:19:29.094176 #27665] INFO -- request: POST https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-02T09:19:29.094507 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"content-type: \"application/json\"\n",
"D, [2018-08-02T09:19:29.094719 #27665] DEBUG -- request: {\"contact_id\":\"21014848\",\"due_date\":\"2018-09-01T23:19:29Z\",\"issue_date\":\"2018-08-01T23:19:29Z\",\"line_items\":[{\"line_item_id\":\"5059216\",\"description\":\"An item sold through Zupply\",\"quantity\":\"1\",\"amount\":\"26.57\"}]}\n",
"I, [2018-08-02T09:19:30.482537 #27665] INFO -- response: Status 400\n",
"D, [2018-08-02T09:19:30.482906 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:18:22 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"400 Bad Request\"\n",
"cache-control: \"no-cache\"\n",
"vary: \"Origin\"\n",
"x-runtime: \"0.742682\"\n",
"x-request-id: \"f16b874f-fd8b-4994-8c7b-80e5bf3376ee\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:19:30.483172 #27665] DEBUG -- response: {\"response\":\"MyOB Bad Request\",\"status\":400}\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd2495ac8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={\"response\"=>\"MyOB Bad Request\", \"status\"=>400} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\", \"content-type\"=>\"application/json\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd2495ac8 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 23:18:22 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"400 Bad Request\", \"cache-control\"=>\"no-cache\", \"vary\"=>\"Origin\", \"x-runtime\"=>\"0.742682\", \"x-request-id\"=>\"f16b874f-fd8b-4994-8c7b-80e5bf3376ee\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=400 @reason_phrase=\"Bad Request\">>"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# no good, try line item id\n",
"invoice = {\n",
" \"contact_id\": contact[\"contact_id\"],\n",
" \"due_date\": 1.month.from_now.utc.iso8601,\n",
" \"issue_date\": DateTime.now.utc.iso8601,\n",
" \"line_items\": [\n",
" {\n",
" \"line_item_id\": item[\"item_id\"],\n",
" \"description\": item[\"description\"],\n",
" \"quantity\": \"1\",\n",
" \"amount\": \"26.57\"\n",
" }\n",
" ]\n",
"}\n",
"conn.post(\"#{user}/invoices\", invoice, { 'content-type' => 'application/json' })"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"No go."
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I, [2018-08-02T09:34:18.940794 #27665] INFO -- request: POST https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices\n",
"D, [2018-08-02T09:34:18.941164 #27665] DEBUG -- request: Authorization: \"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\"\n",
"User-Agent: \"Faraday v0.15.2\"\n",
"content-type: \"application/json\"\n",
"D, [2018-08-02T09:34:18.941451 #27665] DEBUG -- request: {\"contact_id\":\"21014848\",\"due_date\":\"2018-09-01T23:34:18Z\",\"issue_date\":\"2018-08-01T23:34:18Z\",\"line_items\":[{\"line_item_id\":\"5059216\",\"description\":\"An item sold through Zupply\",\"quantity\":1,\"amount\":26.57}]}\n",
"I, [2018-08-02T09:34:20.376066 #27665] INFO -- response: Status 400\n",
"D, [2018-08-02T09:34:20.376449 #27665] DEBUG -- response: server: \"nginx/1.10.3 (Ubuntu)\"\n",
"date: \"Wed, 01 Aug 2018 23:33:12 GMT\"\n",
"content-type: \"application/json; charset=utf-8\"\n",
"transfer-encoding: \"chunked\"\n",
"connection: \"close\"\n",
"status: \"400 Bad Request\"\n",
"cache-control: \"no-cache\"\n",
"vary: \"Origin\"\n",
"x-runtime: \"0.799297\"\n",
"x-request-id: \"2c929923-26be-4f93-a7b7-4f91eb13661e\"\n",
"x-powered-by: \"Phusion Passenger 5.1.12\"\n",
"D, [2018-08-02T09:34:20.376687 #27665] DEBUG -- response: {\"response\":\"MyOB Bad Request\",\"status\":400}\n"
]
},
{
"data": {
"text/plain": [
"#<Faraday::Response:0x00007fffd23f3db8 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body={\"response\"=>\"MyOB Bad Request\", \"status\"=>400} @url=#<URI::HTTPS https://app.gyroapi.com/developers/api/v1/frodo-myob-essential/invoices> @request=#<Faraday::RequestOptions (empty)> @request_headers={\"Authorization\"=>\"bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX2lkIjo1LCJpYXQiOjE1MzExNzk5OTR9.NRyppVtfaGf8Ba2JNZz59aAPBAHCuVMedxwpw_7uZ6evjTB6GdQOlWLbVSkiLSCDxWmWgz3szjFeabxYT5u_vBkT5gKo4_J6kM_pyWapAjlVLKdoGVodNbyeF19Znta_dW5jHcg0PlrNtJ0krm_HbTilHpyGsU_-0L1Zem9mej5XwZx0-KSOeI_5DCxeIO5-860IYxBwSquBmHhJoTCytQjUkA5Nwz2Xq9liPEMGFWo5R_kgqMauVDy8VasZ_Q62Hm0q-SKVjI1U0dpmn-bfupfMq89BTrFSerCRN6wB8yjQ11Y97xmSr-CXs6W820sFoh8gqYkq7Pi44X490mTSsw\\n\", \"User-Agent\"=>\"Faraday v0.15.2\", \"content-type\"=>\"application/json\"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x00007fffd23f3db8 ...> @response_headers={\"server\"=>\"nginx/1.10.3 (Ubuntu)\", \"date\"=>\"Wed, 01 Aug 2018 23:33:12 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"connection\"=>\"close\", \"status\"=>\"400 Bad Request\", \"cache-control\"=>\"no-cache\", \"vary\"=>\"Origin\", \"x-runtime\"=>\"0.799297\", \"x-request-id\"=>\"2c929923-26be-4f93-a7b7-4f91eb13661e\", \"x-powered-by\"=>\"Phusion Passenger 5.1.12\"} @status=400 @reason_phrase=\"Bad Request\">>"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# try using sensible data types instead of strings\n",
"# no good, try line item id\n",
"invoice = {\n",
" \"contact_id\": contact[\"contact_id\"],\n",
" \"due_date\": 1.month.from_now.utc.iso8601,\n",
" \"issue_date\": DateTime.now.utc.iso8601,\n",
" \"line_items\": [\n",
" {\n",
" \"line_item_id\": item[\"item_id\"],\n",
" \"description\": item[\"description\"],\n",
" \"quantity\": 1,\n",
" \"amount\": 26.57\n",
" }\n",
" ]\n",
"}\n",
"conn.post(\"#{user}/invoices\", invoice, { 'content-type' => 'application/json' })"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nope! >:("
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Ruby 2.4.2",
"language": "ruby",
"name": "ruby"
},
"language_info": {
"file_extension": ".rb",
"mimetype": "application/x-ruby",
"name": "ruby",
"version": "2.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment