Hi,
I’m working on an app which integrates with Freeagent. What I’m trying to
achieve should be pretty simple in theory - I just want to be able to
create an estimate (which works fine) whilst at the same time add
estimate_items to it…
I have a variable called freeagent_token which I am making the request
with, and an @job variable which takes the current job/user information.
I’m currently trying to add test data for the estimate_items.
Here is the code for the post request:
freeagent_token.post(‘estimates’, :params => {:estimate => {‘project’ =>
@job.accounts_link,
‘contact’
=> @job.client.accounts_link,
‘dated_on’
=> Date.today,
‘status’
=> “Draft”,
‘estimate_type’ => ‘Estimate’,
‘currency’
=> ‘GBP’}},
‘estimate_items’ =>
[
{
:position
=> 1,
:item_type
=> “Hours”,
:quantity
=> “1.03333333”,
:price
=> “12.2”,
:description
=> “sada”,
:sales_tax_value
=> “20.0”
}
],
:headers
=> {‘Content-Type’ => ‘application/json’, ‘Accept’ => ‘application/json’})
This is based on the freeagent docs:
{ “estimate”:
{
“contact”:“https://api.freeagent.com/v2/contacts/1”,
“reference”:“001”,
“estimate_type”:“Estimate”,
“dated_on”:“2011-09-15”,
“status”:“Draft”,
“notes”:“An example of some additional text.”,
“currency”:“GBP”,
“estimate_items”: [
{
“item_type”:“Hours”,
“quantity”:“1.03333333”,
“price”:“12.2”,
“description”:“sada”,
“sales_tax_value”:“20.0”
}
]
}}
The estimate is created absolutely fine, but the estimate_items just come
out as an empty array.
I’ve tried a PUT request for the estimate too:
freeagent_token.put(“https://api.freeagent.com/v2/estimates/1188030”, :
params => {:estimate =>
{
“estimate_items” => [
{
‘position’ => 1,
‘item_type’ => ‘Hours’,
‘quantity’ => ‘3’,
‘price’ => ‘234’,
‘description’ => ‘test description’,
‘sales_tax_rate’ => ‘20.0’
}
]
}
},
:headers
=> {‘Content-Type’ => ‘application/json’, ‘Accept’ => ‘application/json’})
But this just gives me a very unhelpful error: “Completed 500 Internal
Server Error in 64770ms (ActiveRecord: 0.4ms)”
The docs suggest you can make a direct post request to the estimate_items,
ie: freeagent_token.put(“estimate_items”) but it doesnt recognize this as
valid request.
Can anyone point me in the right direciton?? It’s really hard to find any
ruby/rails specific documentation on this - and I feel like its something
that should be a lot simpler to do!
Cheers
Any views or opinions expressed are solely those of the author and do not
necessarily represent those of Purr Digital Ltd. This email and any
attachments to it may be confidential and are intended solely for the use
of the individual to whom it is addressed. If you are not the intended
recipient of this email, you must neither take any action based upon its
contents, nor copy or show it to anyone. Please contact the sender if you
believe you have received this email in error.