PassKit

FREE
By passkit | Updated 9日前 | Commerce
Health Check

N/A

Back to All Discussions

issues with unirest for php (passkit API)

Rapid account: Jcgalindo
jcgalindo
hace 10 años

Hi!, I’m trying to update a pass through template name, but I’m reciving a null body… this is with UNIREST for PHP…

with UNIREST with NODE.JS works like a charm… but PHP?

<?php

require(dirname(FILE) . ‘/lib/Unirest.php’);
$key = ‘j6WhcWg1sRkXfpz7wBtdQxFdtAW7jSb9’;

$response1 = Unirest::get(
https://passkit-passkit.p.mashape.com/authenticate”,
array(
“X-Mashape-Authorization” => $key
),
null
);

$response = Unirest::put(
https://passkit-passkit.p.mashape.com/pass/issue/template/POC Passkit”,
array(
“X-Mashape-Authorization” => $key,
“Content-Type” => “application/json”
),
json_encode(array(‘data1’ => 1))
);

var_dump($response->body);
?>

RESPONSE:

object(Unirest\HttpResponse)[3]
private ‘code’ => int 400
private ‘raw_body’ => boolean false
private ‘body’ => null <<<<<------------------------------------
private ‘headers’ =>
array (size=2)
‘Content-Length’ => string ‘0’ (length=1)
‘Connection’ => string ‘Close’ (length=5)

THANKS SO MUCH

Rapid account: Passkit
passkit Commented hace 10 años

The issue has to do with the way PHP and curl encapsulate the URL.

Your template name has a space in it. Try replacing the space with %20 and you should find it works.

require(dirname(__FILE__) . '/lib/Unirest.php');
$key = 'j6WhcWg1sRkXfpz7wBtdQxFdtAW7jSb9';
$response = Unirest::put( "https://passkit-passkit.p.mashape.com/pass/issue/template/POC%20Passkit", 
    array( "X-Mashape-Authorization" => $key, 
           "Content-Type" => "application/json" ), 
    json_encode(array('data1' => 1)) );

var_dump($response);```

There is no need to authenticate before sending the main request.

Also we would strongly recommend that you revoke your Mashape key, since a malicious user who sees it published here could use it to access your account.
Rapid account: Jcgalindo
jcgalindo Commented hace 10 años

Wow, so easy…

Thanks so much guys!!!

Join in the discussion - add comment below:

Login / Signup to post new comments