2

I am trying to make a POST request to the GETResponse API(https://apidocs.getresponse.com/v3/case-study/adding-contacts) with thephpleague/oauth2-client and adespresso/oauth2-getresponse as a provider like so:

  $data = [
            'email' => $email,
            'campaign' => [
                'campaignId' => $campId
            ]
        ];
    $request = $this->provider->getAuthenticatedRequest(
                        'POST',
                        'https://api.getresponse.com/v3/contacts',
                        $this->getMyAccessToken(),
                        $data
            );
    $response = $this->provider->getParsedResponse($request);

I also tried this passing in content type value of application/json in the headers all to no avail.

$data = [ 'email' => $email, 'campaign' => [ 'campaignId' => $campId ] ];

    `$options['body'] = json_encode($data);
    $options['headers']['Content-Type'] = 'application/json';
    $options['headers']['access_token'] = $this->getMyAccessToken();
    $request = $this->provider->getAuthenticatedRequest(
                        'POST',
                        'https://api.getresponse.com/v3/contacts',
                        $options
            );
    $response = $this->provider->getParsedResponse($request); `

However the getParsedResponse function in both approaches returns the following:

League \ OAuth2 \ Client \ Provider \ Exception \ IdentityProviderException (400) UnsupportedContentTypeheader.

2 Answers 2

6

I know it's late, but try this code:

$data = array(
  'email' => $email,
  'campaign' => array([
    'campaignId' => $campId
    ])
);

$options['body'] = json_encode( $data );
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['Accept'] = 'application/json';
$request = $this->provider->getAuthenticatedRequest( 'POST', 'https://api.getresponse.com/v3/contacts', $this->getMyAccessToken(), $options );
$response = $this->provider->getParsedResponse( $request );
1
  • This worked for me for Bitly API as well. One thing if you're debugging Bitly: group_guid is also required, even though documentation doesn't say so.
    – Paul Nowak
    Commented May 5, 2019 at 23:32
2

Passing POST data with json_encode() didn't work for me, I tried different solutions but that's the only one that worked for me

$postData = [
    'date' => $date,
    'service_ids' => $serviceId,
];
$options = [
    'body' => http_build_query($postData),
    'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
    ],
];

$request = $this->provider->getAuthenticatedRequest("POST", $requestUrl, $token, $options);
$response = $this->provider->getParsedResponse($request);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.