PassKit

무료
분류별 passkit | 업데이트됨 vor 21 Tagen | Commerce
Health Check

N/A

모든 토론으로 돌아가기

issues with unirest for php (passkit API)

Rapid account: Jcgalindo
jcgalindo
vor 10 Jahren

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 vor 10 Jahren

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 vor 10 Jahren

Wow, so easy…

Thanks so much guys!!!

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입