APIs & Integrations

aolvikash
Participant

What is the HubSpot API Package for Perl

Hi, 

 

Could you please help me understand the Perl API packages for HubSpot?

0 Upvotes
6 Replies 6
SCatlin
Participant

What is the HubSpot API Package for Perl

I've been doing some work in Perl as well.  I didn't find any packages out there to be much help.  I ended up using the REST::Client module available on cpan.  It works pretty well.  Here's my (modified) code I use to add a Deal if it helps.

sub addOrder {

	# This function is part of a custom module, so grab the instance of the REST::Client
	#  class and the hash containing the properties to be added to the Deal
	#  So, any reference to $self is a reference to the REST::Client class.
	my ($self, $properties) = @_;
	
	# Grab the company id and then delete it.  Need to save it so we can associate the company with the
	#  deal after we create the deal.  Don't need the company id when creating the Deal.
	my $companyId = $properties->{company_id};
	delete $properties->{company_id};
	
	# Build the query and the JSON payload then add the deal
	my $query = qq(/crm/v3/objects/deals?hapikey=$hapikey);
	my %dataHash = ( 'properties' => $properties );
	
	# My custom module includes a JSON module instance
	my $data = $self->{json}->encode(\%dataHash);
	$self->POST($query, $data);
	my $response = $self->{json}->decode( $self->responseContent() );
	my $responseCode = $self->responseCode();
	if( substr($responseCode, 0, 1) ne '2' ) {
		die qq(HubSpot API Error Creating a Deal - HTTP Code $responseCode:\n$self->responseContent()\n\n$data\n );
	}
	my $dealId = $response->{id};

	# Associate the deal and company using the id from the newly created deal
	#  and the company id saved earlier
	$query = qq(/crm/v3/objects/deals/$response->{id}/associations/companies/$companyId/deal_to_company?hapikey=$hapikey);
	$query =~ s/[\n\t]//g;
	$self->PUT($query);
	$responseCode = $self->responseCode();
	if( substr($responseCode, 0, 1) ne '2' ) {
		die qq(HubSpot API Error Associating Company to Deal - HTTP Code $responseCode:\n$data\n );
	}
		
} #end addOrder()

 

So, it's a pretty simple module to use and access the HS API with.

 

Hope that helps.

 

-Scot

aolvikash
Participant

What is the HubSpot API Package for Perl

Thanks, @SCatlin.

 

Could you please share the other part of the script where you call the function "addOrder", I want to understand how the properties are pass into function and collected here. Need to work on the Ticket object to create the case.

 

I know we don't have an API package option for Perl on HubSpot, So I have to do it REST API call only!

 

SCatlin
Participant

What is the HubSpot API Package for Perl

@aolvikashI just PM'd you with a code sample.

aolvikash
Participant

What is the HubSpot API Package for Perl

Thanks a lot @SCatlin 

aolvikash
Participant

What is the HubSpot API Package for Perl

Thanks, @SCatlin. However, I have a lot of work to do from Perl to HubSpot such as updating Asset info, Creating tickets, adding comments on Tickets, collecting companies' info, and many more.

 

Looking for an efficient way to do this!!

 

Can anyone please help on this  @ArturMudrytsk?

 

 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

What is the HubSpot API Package for Perl

Hello @aolvikash 

Adding @ArturMudrytsky to the convo to see if they have any help here

0 Upvotes