scoop / autotask_api Goto Github PK
View Code? Open in Web Editor NEWRuby API wrapper for the Autotask WebService API
License: MIT License
Ruby API wrapper for the Autotask WebService API
License: MIT License
Kinda off topic, but what's the best way to handle this situation?
An example is that you make a call for "ServiceCall" and then later ticket and contact. In this case, for whatever reason, no contact was returned for the ticket and thus the following method call will throw an undefined method error.
ticket.contact.first_name
To some degree, it seems that the issue happens most when there are +2 queries to be made. For example, in the case of ServiceCall, to get the resource you have to query through service_call_ticket
and service_call_ticket_resource
to get resource
, which if no resource is associated, then this method would fail service_call.service_call_ticket.service_call_ticket_resource.resource
Is there a way to adjust this lookup so that the API doesn't throw an unknown method and instead would return something useful.
Sorry if this doesn't exactly make sense.
While running the sample code, I am presented with the following error.
D, [2015-07-06T17:53:36.391415 #53230] DEBUG -- : HTTPI GET request to webservices3.autotask.net (httpclient)
I, [2015-07-06T17:53:36.697307 #53230] INFO -- : SOAP request: https://webservices3.autotask.net/ATServices/1.5/atws.asmx
I, [2015-07-06T17:53:36.697455 #53230] INFO -- : SOAPAction: "http://autotask.net/ATWS/v1_5/query", Content-Type: text/xml;charset=UTF-8, Content-Length: 346
D, [2015-07-06T17:53:36.703347 #53230] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://autotask.net/ATWS/v1_5/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<tns:query xmlns="http://autotask.net/ATWS/v1_5/"/>
</env:Body>
</env:Envelope>
D, [2015-07-06T17:53:36.703852 #53230] DEBUG -- : HTTPI POST request to webservices3.autotask.net (httpclient)
I, [2015-07-06T17:53:37.147121 #53230] INFO -- : SOAP response (status 200)
D, [2015-07-06T17:53:37.147504 #53230] DEBUG -- : <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<queryResponse xmlns="http://autotask.net/ATWS/v1_5/">
<queryResult>
<ReturnCode>-1</ReturnCode>
<EntityResults/>
<EntityResultType/>
<Errors>
<ATWSError>
<Message>Object reference not set to an instance of an object.</Message>
</ATWSError>
<ATWSError>
<Message>Error reading in Query XML.</Message>
</ATWSError>
</Errors>
<EntityReturnInfoResults/>
</queryResult>
</queryResponse>
</soap:Body>
</soap:Envelope>
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><queryResponse xmlns="http://autotask.net/ATWS/v1_5/"><queryResult><ReturnCode>-1</ReturnCode><EntityResults /><EntityResultType /><Errors><ATWSError><Message>Object reference not set to an instance of an object.</Message></ATWSError><ATWSError><Message>Error reading in Query XML.</Message></ATWSError></Errors><EntityReturnInfoResults /></queryResult></queryResponse></soap:Body></soap:Envelope>
Cursory googling appears to say that this is an issue with the XML formatting, but as far as I can tell all of the Nokogiri XML builders spit out perfectly good requests. Thoughts?
Thanks!
Jacob
We needed to use more fields in the account entity, and we added them by extending the account class in our app like this:
AutotaskAPI::Account.class_eval do self.fields = fields + %i[account_number phone alternate_phone1 alternate_phone2 fax bill_to_address1 bill_to_address2 bill_to_city bill_to_zip_code bill_to_state] end
How about I add these extra fields to the account class it self and create a PR?
So that others who need these fields don't have to this.
I'm not even sure if this is correct, but it seems so.
I have a couple of different classes that do something like so.
class ZoneInfoService
attr_accessor :client
def initialize(args)
self.client = AutotaskAPI::Client.new do |c|
c.endpoint = 'https://webservices2.autotask.net/ATServices/1.5/atws.asmx'
end
end
end
Somehow it seems that the client
is being shared across the classes. I see this because the c.endpoint should be different between the different classes, but instead, it's the original value. Am I going looney?
Do you mind if I submit a PR that adds tests? It wouldn't be complete, but some of the basics, at least something to get started.
In Autodesk, multiple resources can be assigned to a single ServiceCall. Here's an example snip.
I believe it should be has_many
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<queryResponse xmlns="http://autotask.net/ATWS/v1_5/">
<queryResult>
<ReturnCode>1</ReturnCode>
<EntityResults>
<Entity xsi:type="ServiceCallTicketResource">
<id>671</id>
<UserDefinedFields/>
<ServiceCallTicketID xsi:type="xsd:int">592</ServiceCallTicketID>
<ResourceID xsi:type="xsd:int">29682894</ResourceID>
</Entity>
<Entity xsi:type="ServiceCallTicketResource">
<id>673</id>
<UserDefinedFields/>
<ServiceCallTicketID xsi:type="xsd:int">592</ServiceCallTicketID>
<ResourceID xsi:type="xsd:int">29682885</ResourceID>
</Entity>
</EntityResults>
<EntityResultType>servicecallticketresource</EntityResultType>
<Errors/>
<EntityReturnInfoResults>
<EntityReturnInfo>
<EntityId>671</EntityId>
<DatabaseAction>None</DatabaseAction>
<DuplicateStatus>
<Found>false</Found>
<Ignored>false</Ignored>
</DuplicateStatus>
</EntityReturnInfo>
<EntityReturnInfo>
<EntityId>673</EntityId>
<DatabaseAction>None</DatabaseAction>
<DuplicateStatus>
<Found>false</Found>
<Ignored>false</Ignored>
</DuplicateStatus>
</EntityReturnInfo>
</EntityReturnInfoResults>
</queryResult>
</queryResponse>
</soap:Body>
Any chance you could post an example of an update and create call?
While running the sample code, I am presented with the following error.
D, [2015-07-06T17:53:36.391415 #53230] DEBUG -- : HTTPI GET request to webservices3.autotask.net (httpclient)
I, [2015-07-06T17:53:36.697307 #53230] INFO -- : SOAP request: https://webservices3.autotask.net/ATServices/1.5/atws.asmx
I, [2015-07-06T17:53:36.697455 #53230] INFO -- : SOAPAction: "http://autotask.net/ATWS/v1_5/query", Content-Type: text/xml;charset=UTF-8, Content-Length: 346
D, [2015-07-06T17:53:36.703347 #53230] DEBUG -- :
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://autotask.net/ATWS/v1_5/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
env:Body
<tns:query xmlns="http://autotask.net/ATWS/v1_5/"/>
/env:Body
/env:Envelope
D, [2015-07-06T17:53:36.703852 #53230] DEBUG -- : HTTPI POST request to webservices3.autotask.net (httpclient)
I, [2015-07-06T17:53:37.147121 #53230] INFO -- : SOAP response (status 200)
D, [2015-07-06T17:53:37.147504 #53230] DEBUG -- :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
soap:Body
-1
Object reference not set to an instance of an object.
Error reading in Query XML.
/soap:Body
/soap:Envelope
Cursory googling appears to say that this is an issue with the XML formatting, but as far as I can tell all of the Nokogiri XML builders spit out perfectly good requests. Thoughts?
Thanks!
Jacob
I haven't been able to make the getZoneInfo call as required by AutoTask. AT has multiple zones and depending on your userID a specific zone is required. This also affects the wsdl URL.
Any thoughts on this?
This logic comes into play in the initialize section
def initialize
yield self
self.savon_client ||= Savon.client do |c|
#c.basic_auth basic_auth
c.wsdl wsdl
# endpoint is depending on authentication. Must be queried and pulled from AutoTask for the correct Endpoint
c.endpoint 'https://webservices2.autotask.net/ATServices/1.5/atws.asmx'
c.pretty_print_xml true
c.raise_errors true
c.log true
c.log_level :debug
end
Entity.client ||= self
end
Would it be possible to support a proxy with the client?
Additionally, pass in the parameter to ignore client certificates. http.auth.ssl.verify_mode = :none
The reason is that something broke with the Autotask API and now all these calls are broken and I need to be able to debug the actual SOAP call.
I'm trying to get all time entries for a ticket within the last year.
Is there a specific Condition for comparing dates ?
query = AutotaskAPI::QueryXML.new do |query|
query.entity = 'timeentry'
end
year_ago = (DateTime.now - 1.year).to_formatted_s(:iso8601)
query.add_condition('ticketid', 'equals', ticket_id)
query.add_condition('type', 'equals', 2)
query.add_condition('dateworked', 'GreaterThan', year_ago)
@client.query = query
I'm trying to use this gem to write queries with multiple conditions. I was wondering if there was an example you could provide as I have not been able to get it to work yet, from the information in the README
https://gist.github.com/trepidity/7537734
Trying to create a sample call, but I'm getting
sample_query.rb:16:in `
See my gist for the code I'm using.
The commands I'm ran first are
gem build autotask_api.gemspec
gem install autotask_api
gem list|grep autotask
autotask_api (0.0.7)
Thanks.
From what I can tell, AutoTask API is throwing a 500 error if the authorization header is included when the client does a GET for the WSDL.
For example, get_zone_info fails unless you drop the basic auth header.
The first call that the client makes, is to https://webservices.autotask.net/atservices/1.5/atws.wsdl
and the basic auth header is included. This URL is not protected and the basic auth header is not needed.
It appears that Savon made this change in 2.0 or 2.1 to support servers that protect the WSDL. I cannot find a way to disable this in the Savon client.
I want to pull back all tImeEntry records that have a type of 1 or 2. how would i go about constructing that using an add_condition block ?
query = AutotaskAPI::QueryXML.new do |query|
query.entity = 'timeentry'
end
year_ago = (DateTime.now - 1.year).to_formatted_s(:iso8601)
query.add_condition('ticketid', 'equals', ticket_id)
query.add_condition('type', 'equals', 2) || query.add_condition('type', 'equals', 1)
I'm trying to pull back all active accounts and seem to be only getting A-B and none of the other records. Is the response paginated / how can I handle this.
I saw an email those days about a transition
"America West (ww5.autotask.net) to America West 2 (ww15.autotask.net)".
Do you think it's going to impact us ?
It also says:
If you are using our custom API, be sure to modify all of your APIs so that they are using getZoneInfo() instead of zone-specific URLs. Please check any third party vendor information or contact them directly prior to this change to be sure they are using getZoneInfo().
The change week is April 11th, so regarding their (unprofessionally) very short notice, I am starting to feel anxious.
autotask_api/lib/autotask_api/client.rb
Line 29 in 934cb57
AutoTask is requiring an IntegrationCode to be passed in the header. I implemented it, but I feel it's hacky. Would you have a suggestion on how to better implement?
Here's how I did it.
def create(xml)
savon_client.call :create, message: "<Entities>#{xml}</Entities>",
attributes: { xmlns: NAMESPACE },
soap_header: {
'tns:AutotaskIntegrations' => {'tns:IntegrationCode' => ENV['IntegrationCode']}
}
end
So I've gotten to where I can run the zoneinfo test and get back my correct URL.
I feel like I'm probably missing something for the actual test code. If I do a "puts client.query" it just spits back the XML
<sXML><![CDATA[<queryxml>
<entity>contact</entity>
<query>
<field>firstname<expression op="equals">Joe</expression></field>
</query>
</queryxml>]]></sXML>
I'm sure this is due to me being pretty new to ruby but maybe you could point me in the right direction?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.