1

I'm attempting a GET request to acquire an email_token with Guzzle HTTP that looks like this:

$email = $customer['attributes']['Email'];

    $client = new Client();
    $res = $client->request('GET', 'https://www.example.com/apps/api/Services/Email/Opting', [
        'email' => $email
    ]);
    dd($res->getBody());

The response is returning 200/OK, but I'm not getting the email_token as expected. The sparse API docs I'm working off give a very similar example and state the expected response's content should look something like this:

{
    "email": "[email protected]",
    "marketing": true,
    "promotional": true,
    "news": true,
    "feedback": true,
    "account_related": true,
    "token": "eyJpdiI6Ik9tNlFwbEorbjNnK1FsNnFZb1ZtaFE9PSIsInZhbHVlIjoibGNheWpDR0Z6eWpcL1VCbjdsUXZCS0lzRURBZTIzMVc5ZXRTamQrd1dQTFE9IiwibWFjIjoiYTEwYTM2ODU0MmQzMTY5NGIwNWFhOWFjM2ZiZTBkMzkzOWMyY2VkYTMzNjk5ZDYyOTE0OGY2YjBhNGNkYjk4NyJ9"
}

Once I get the token, I then need to make a POST with a couple more requirements (one being the email_token) in order to automate a customer's ability to opt out of the mailing list. Any thoughts on why my response is coming back like this?

Screenshot of dd($res);

Screenshot of dd($res->getBody());

0

1 Answer 1

2

In order to get the response payload you should do:

$response = $res->getBody()->getContents();

To get the status:

$responseStatus = $res->getStatusCode();

documentation for more: Guzzle

Sign up to request clarification or add additional context in comments.

17 Comments

That's returning HTML, but it looks like there might be an email_token in a meta tag: <meta name="csrf-token" content="DfGukea4gUxbUWdAhkz3tnb6AFVmcwG3yv0EF22D">?
hmm what if you dd $res->getHeaders();
That looks like this: array:10 [▼ "Date" => array:1 [▶] "Server" => array:1 [▶] "X-Powered-By" => array:1 [▶] "Cache-Control" => array:1 [▶] "X-Mod-Pagespeed" => array:1 [▶] "Vary" => array:1 [▶] "Content-Length" => array:1 [▶] "Content-Type" => array:1 [▶] "Set-Cookie" => array:2 [▶] "Connection" => array:1 [▶] ]
there is no token in the headers what if you try dd(json_decode($res->getBody()->getContents(), true);
Yeah, tried that and it's null. Perhaps it's the API?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.