0

When i do a POST Request with Postman to the API of pushpad (https://pushpad.xyz/docs/rest_api) it works as expected and i get the push notification on desktop. However, when i do it manually it just shows some broken HTML Code which seems to be the Dashboard of Pushpad. I get no error at all, i get a status code 200 saying OK.

I have already tried the following:

$client = new Client([
            'headers' => [ 'Content-Type' => 'application/json' ],
            ['Authorization' => 'Token token="for the sake of privacy removed in this question"'],
            ['Accept' => 'application/json'],
        ]);

        $response = $client->post('https://pushpad.xyz/api/v1/projects/1234/notifications', [
                'json' => [
                    ['body' => 'testbody' , 'title' => 'testtitle']
                ]
            ]);
        echo '<pre>' . var_export($response->getStatusCode(), true) . '</pre>';
        echo '<pre>' . var_export($response->getBody()->getContents(), true) . '</pre>';
        dd($response->getBody()->getContents());

I get a status code of 200 and for the content or body i just get a simple ' So the question is, why does it work in Postman but not manually. (Using Laravel 5.5, Guzzle) See the image for more details on what i did in postman and the result my manual code gave me. (Params are empty) Thanks a lot! image

Desory
  • 83
  • 2
  • 11
  • are you getting the response on the right way? https://stackoverflow.com/questions/30549226/guzzlehttp-how-get-the-body-of-a-response-from-guzzle-6/30549372 – Isaac Gomes Mar 23 '19 at 16:34
  • If it is correct, it should send a push notification like postman does but nothing happens. And also i realised that if i reload the page i get something similiar looking but only for a split of a second and then the content in the image overwrites the page. – Desory Mar 23 '19 at 17:01
  • after trying around some i get the exact same thing i got in the img, the entire dashboard of pushpad. as a string, as everything. – Desory Mar 23 '19 at 17:23

1 Answers1

0

Look at your header's section braces.

new Client([
  'headers' => [
    'Content-Type' => 'application/json',
    'Authorization' => 'Token token="for the sake of privacy removed in this question"',
    'Accept' => 'application/json',
  ],
]);
SiZE
  • 2,217
  • 1
  • 13
  • 24
  • Thanks a ton! For future reference, if i have something "new" like this now, where do I look that up , because neither guzzle nor json headers returned this information on the syntax, everbody expects that you just know how it works since you were born. – Desory Mar 23 '19 at 23:04
  • @user11186057 I think docs should helps http://docs.guzzlephp.org/en/stable/request-options.html#headers – SiZE Mar 24 '19 at 06:03