PHP - While creating pass from Wallet API getting an error "Error parsing JSON request string,msg= null"

Hello,


With PHP, i am trying to generate pass from one of the template of  my project. Below is my code, which is  not working. Use below code, change template id, login email and API key to check this.

 

 

    $fields = array(
        'publicURL' => 'single',
        'msg' => 'Testing msg only.',
        'Passenger' => 'Test Passenger',
        'Boarding Pass Details' => 'This text is automated'
    );
                
    $create_pass = get_curl_data('https://wallet-api.urbanairship.com/v1/pass/123456', $fields);
    $create_passArr = json_decode($create_pass);
    echo rand();
    echo '<pre>';
    print_r($create_passArr);
    echo '</pre>';
    

    function get_curl_data($url, $fields){
        //open connection
        $ch = curl_init();
        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_USERPWD, 'xxxxLOGINEMAILxxxx:xxxxAPIKEYxxxx');
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));

        //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded', 'Api-Revision:1.2'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

        //execute post
        $result = curl_exec($ch);
        //close connection
        curl_close($ch);
        return $result;
    }

 

 

After executing above code, i am getting below error message.

stdClass Object
(
    [code] => 406
    [description] => Not Acceptable Request.
    [details] => Error parsing JSON request string,msg= null
)

 

Can anyone help me on this?

 

Thanks

Didn't find what you were looking for?

New post

Comments

2 comments

  • I resolve it. Just replace below lines with current code.

    $json_data = json_encode($fields);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $json_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Content-Length: ' . strlen($json_data) , 'Api-Revision:1.2'));

     

    Hope this helps.

    Thanks.

    0
  • Hi Mohit,

    Thank you for providing the resolution in this forum.

    Please let us know if there is any more we can do.

    My Best,
    Aaron Schuman
    Technical Support Engineer, Portland

     

    0

Please sign in to leave a comment.