Sending a PUT request from PHP to Hubspot - php

This problem is really bugging me, i'm a hobby programmer who right now is trying to follow the simple instructions of Hubspots CRM API documentation.
I've managed to retrieve and POST information from and to Hubspot using cURL/PHP, but now i'm facing an update(PUT) and i can figure it out.
I'm trying to associate a "Deal" with a "Contact" inside the CRM, it seems to be so easy, just fire away a url? :)
The documentation on the API says:
Note: You only need to use this endpoint when updating existing deal records. If you are creating new deals, you can make these associations when creating the record by including the associations data as documented on the create deal page."
src: https://developers.hubspot.com/docs/methods/deals/associate_deal
Do i understand correctly, i tried to use this URL in my browser and expected an update to happen?
https://api.hubapi.com/deals/v1/deal/DEALID/associations/CONTACT?id=CONTACTID&hapikey=MyKey
The response i got in the browsers console was: 405 (Method not allowed).
I tried to fire the url though cURL aswell, but got lost right away because i dont really have any data to send in "CURLOPT" parameters, the data should, if i understand correctly be inside the endpoint url.
If you have any idea of what this hobby programmer doesnt understand, please reply :)
Kind regards,
Simon

Related

Developing REST API using PHP

I am new in API. I am supposed to develop an API that allows our content provider to give information pertaining soccer whereby he is supposed to create matches,update matches etc .I would like to know how to create a REST API in php that allows a client to enter the information. So far,I have created an API but I dont know how to enable the client enter the information.
Informations:
It is the basic form that you have to create and then you must allow the user to submit the form datas that he/she has filled and you have to post the data to the route that you have created.
You must submit the data and then you have to make the submitted data to be json_encode() so that it will work for the API.
Or Else if you are not designing the form and other such things you can directly go in for the API ADD ONS that the Firefox and the chrome has . Assuming you are using the chrome or Firefox as browsers.
https://addons.mozilla.org/en-US/firefox/addon/restclient/
https://addons.mozilla.org/en-US/firefox/addon/rest-easy/
https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en
Okay, assuming that you created a REST API already, download the Advanced REST client chrome extension: https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
I hope that answers to your question.
P.S: May I know what framework did you use to design your REST API ? Additional details can help you further.
Building REST APIs is atually a rather easy task. That's primarily what I work on at work all day. If you have to use PHP (I'm a fan of PHP, so don't take that comment the wrong way :) ), I would reccommend using a framework like Laravel.
The logic to handle the information once it's requested wouldn't change. You would just need to make your requests/responses REST compliant.
Here is a great tutorial for doing just that!
Also, since you use Yii, this tutorial is probably better. I've never used Yii, so I can't really vouch for it, though.

Ionic 2 / Laravel 5.2 communication with the API

Im a mega newbie at Ionic 2 and Angular 2, but i have quite a bit of background in PHP.
I have built my API in Laravel 5.2, at the moment, i have a login URL as follows:
http://www.website.com/api/v1/login
Which obviously returns a token if login is successful.
I have also built a form in ionic 2 using CSS and HTML, which is in the default /app/pages/home/home.html
What i want to do is make the login form actual communicate with the API but i cant find any examples on how to do this in Ionic v2.0.0-beta.32
All i want to do is redirect to a blank page if successful or display an alert if it fails.
I would love if someone could give me a bit of a helping hand.
Respect.
I am not sure what exactly you mean with "make the login form actual communicate with the API".
If you mean the actual http communication you'd need to understand $http and Observables. If you search for those terms you will find plenty of information and examples.
If that is not what you mean please be more specific.
I've tried a similar solution connection laravel to ionic 2.
From what I've learned, after you connect to laravel, you'll get the token, and this token will be used in all the requests to laravel/api.
Check for jwt-auth and satelizer for the angular authentication.
Some links that may help:
https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps
https://github.com/sahat/satellizer/tree/master/examples/ionic
The first one is to prepare the laravel part, the second for the ionic.
NOTE:: In the first link, I faced some issues and problems, not with the code, but with the reference links.
Ex:
'JWTFactory' => Tymon\JWTAuthFacades\JWTFactory::class
should be
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class
It's missing some backslashes.

Facebook graph command creating duplicate album

I've been using the Facebook php sdk to interact with facebook quite successfully. When I tried to create a photo album the code created a duplicate. At first I thought it was the php sdk (using 3.x). I tried switching to Perl with LWP::UserAgent and LWP::Simple::Post to use the http url for graph. Nothing is working. Every way I try I get double albums when I call the code. I've ensured that the code is being called once (mainly because I've created a super small test script to do it and have made outputs to ensure on the command line that it's only calling once.
Here's the url I'm using:
https://graph.facebook.com/me/albums?access_token=<access_token>&name=Test+Album+2&message=Test+Description
I've taken off the privacy setting from the url and it hasn't changed the behavior. If I run this directly in the graph explorer, it creates only one album. But any other method (yes, I am using POST and not GET and yes I've tried to pass all the params as post data individually rather than via querystring, either way results in duplicate albums) causes duplicate albums.
Has anyone experienced this? How do I fix it??? I'm at my wits end trying to figure this out.
I've tried it on multiple servers in thoughts that perhaps one of them was using a proxy causing the duplicate call, but whether I run it on my hosting service or on my localhost, I still get duplicates.
No matter what I've tried, if I am creating the album via code in PHP or Perl I get double albums created. HELP!
My first answer was deleted for some reason so I'm not sure what to do at this point. This question can't be answered because:
The issue was not with the SDK but with Facebook itself. I had created a bug report after doing some more tests. Facebook confirmed and fixed the bug. Basically, it had to do with inappropriate permissions handling.
https://developers.facebook.com/bugs/1435856773345641/
There was a bug in Facebook's handling in this instance. I'm hoping this answer doesn't get deleted because someone else may experience this and want to know that it was a bug in Facebook code, not in the PHP SDK or in the user code.
Not sure why Andrew Barber would delete that answer.
Unless someone has a better answer than what Facebook gave to me via bug report follow-up.

Searching twitters public timeline using JQuery

So a while back I used to use the twitter json search in one of my apps but it seems since the change in API versions there has been some major changes which even after reading the documentation I still can't get my head around and it really doesn't make it very easy to understand so hopefully one of you tech guys out there can help me out.
I want to clean my application up so it works again in plainly doing the following:-
http://search.twitter.com/search.json?
q='+param+'&
rpp=100&
result_type=recent&
lang=en
Obviously with the changes this is no longer possible but I want to be able to do this again using the new address but in JQuery unless someone can suggest either a tutorial or a piece of code or even a link to a topic where I could get my answer. I'm also open to using PHP as this is what I used at one point with searching Facebook's timeline and you can get an access token using $.get() for Facebook so surely it would be the same with Twitter too?
Any advice/code is welcome.
Thanks!
the search API needs authorization now. I'd say that, first off, you need to call the https url not http.
With Abhramam William's library you'd do something like the following, after having received your app's bearer token:
$your_tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=from:grey_mina&result_type=recent&count=5");

Google Maps Places Details request (PHP)

I read so many messages with that REQUEST_DENIED error but I still couldn't figure out why it's not working! My google API key has Places and Gmap v3 services activated. The key is working since my Autocomplete app is working with it. I'm also using the same domain as my Autocomplete app. I'm trying to check a place's details with its reference.
To spare you all my attempts, let's say I use this class and here is my code:
require('googlePlaces.php');
$g = new googlePlaces("MyGoogleAPIKey");
$g->setLanguage("fr");
$g->setReference($_GET['ref']);
var_dump( $g->details() );
But I kinda doubt that this is a code problem, since when I type the URL in the browser it should work, no?
When I echo the $URLToCall I have this. And that URL in a browser give me a REQUEST_DENIED.
I'm lost :(
Thanks for any hints!
Ok folks, I kind of hate myself.
I lost 2 days trying to figure out what was going wrong.
For I don't know what reasons, I had to create a new project and get a new API key.

Categories