APIs & Integrations

Wallace
Participant

Error 415 when creating engagements

Résolue

Hi,

 

I see the common solution for a 415 error is to include the correct header eg:

Content-Type: application/json

 

I think I am doing this in my php code but since its not telling me what the content type it's recieving in the error msg, I can't tell why its not working.

 

Is there a place I can view the logs of my API requests?

 

I have tried with v1 and v2 and I have also tried "application/json; charset=utf-8"

 

My php 5.4 code that is attempting to link an already uploaded fila (via API sucecessfully) with an existing Deal - via a new Egagement Note - as that appears to be the only way to link a file with a Deal:

 

 

 

$haipkey = "my-personal-api-key";
$post_url = "http://api.hubapi.com/engagements/v1/engagements?hapikey={$hapikey}";

$post = array();
$post['engagement'] = array(
 'active' => true, 
 'type' => 'NOTE', 
 'timestamp' => 1409172644778
);
$post['associations'] = array(
'contactIds' => array(), 
'companyIds' => array(), 
'dealIds' => array('3958590140'), 
'ownerIds' => array(),
);
$post['attachments'] = array( 'id' => '40471232501');
$post['metadata'] = array('body' => 'Note just to attach a file');

//var_dump(json_encode($post));

$headers = array("Content-Type" => "application/json"); 
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

if (!$result = curl_exec($ch)) {
trigger_error(curl_error($ch));
}
curl_close ($ch);

print $result;

 

 

0 Votes
1 Solution acceptée
Wallace
Solution
Participant

Error 415 when creating engagements

Résolue

Found my problem.. incorrect header and attachment structures.

 

Should have been:

curl_setopt($ch, CURLOPT_HTTPHEADER,  array('Content-Type:application/json'));

and:
$post['attachments'] = array(array( 'id' => '40471232501'));

Voir la solution dans l'envoi d'origine

8 Réponses
Wallace
Participant

Error 415 when creating engagements

Résolue

This PHP code works and does not get the 415 error as I not form the headers correctly:

$hapikey = 'my-personal-api-key';
$post_url = "http://api.hubapi.com/engagements/v1/engagements?hapikey={$hapikey}";

$post = array();
$post['engagement'] = array('active'=> true, 'type' => 'NOTE', 'timestamp' => 1409172644778);
$post['associations'] = array(
  'contactIds' => array(), 
  'companyIds' => array(), 
  'dealIds' => array('3958590140'), 
  'ownerIds' => array(),
 );
$post['attachments'] = array(array( 'id' => '40471232501'));
$post['metadata'] = array('body' => 'Note just to attach a file');

var_dump(json_encode($post));
print "<hr/>\n";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,  array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));

if(! $result = curl_exec($ch)) {
  trigger_error(curl_error($ch));
}

curl_close ($ch);

print $result;

 

 

Wallace
Participant

Error 415 when creating engagements

Résolue

The editor doesn't like me pasting in code today so I can't post the final working code for others to benifit from 😞

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Error 415 when creating engagements

Résolue

@Wallace !

Thanks for posting what you could.  Wonder if it will work today.  If not, could you send me the error that you received?

 

0 Votes
Wallace
Solution
Participant

Error 415 when creating engagements

Résolue

Found my problem.. incorrect header and attachment structures.

 

Should have been:

curl_setopt($ch, CURLOPT_HTTPHEADER,  array('Content-Type:application/json'));

and:
$post['attachments'] = array(array( 'id' => '40471232501'));

dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Error 415 when creating engagements

Résolue

Hi @Wallace 

For engagements, you will have to use the V1 as it is still in development.

What is the json that is outputed from that request just to make sure it is being properly formatted.  Looks correct, but just in case 😀

I also just noticed that your variable holding the hapikey is spelled differently than in the request url.

0 Votes
Wallace
Participant

Error 415 when creating engagements

Résolue

Hi Dennis,

 

I get the same result when I try v1 and v2

Problem accessing /engagements/v1/engagements. Reason:

Unsupported Media Type

 

Trying v3 give me a 404 as expected.

 

Nothing shows in my Settings / Integrations / API key / Call log (from this specific POST - I see other POST and GETs ok).

 

Im trying to add an engagement, associated with a Deal, that has a pre-uploaded file (via a previous API POST) attached.

 

The json looks like this:

{
  "engagement": {
    "active": true,
    "type": "NOTE",
    "timestamp": 1409172644780
  },
  "associations": {
    "contactIds": [],
    "companyIds": [],
    "dealIds": [
      "3958590140"
    ],
    "ownerIds": []
  },
  "attachments": {
    "id": "40471232501"
  },
  "metadata": {
    "body": "Note just to attach a file"
  }
}

 

My aim is to link a whole batch of files (screenshots pdfs etc..) with Deals and Tickets I will be importing via the standard CSV method.

 

All insights welcome.

 

 

 

Wallace
Participant

Error 415 when creating engagements

Résolue

Thanks Dennis.. I see the page and can see some logs.

 

I change the filters to show as much as possible but Im not seeing my attempts to POST Engagements, only POSTs that attached some files and many GETs to read data.


When I click on a successful 200 POST I see 'No header where recorded for this request' in all four resuest, response, header, body.   I assume since it was OK nothing is recorded.

 

My 409 and 500 attempts do have useful info logged.. which is great.

 

I just need to work out why my failing 415 POSTs are not logging in the first place.

 

Maybe becuase Im using the v1 API?

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Error 415 when creating engagements

Résolue

Hey @Wallace 

Per this changelog, you can access last 7 days of API calls.

 

0 Votes