0

I was wanting some help please to create a snippet of cURL to call an API.

Any assistance would be greatly appreciated.

This is the API Call

POST https://api.passes.com/v1/templates/names/Member%20Card/pass

apparently they need the following sent

------------------------------330184f75e21
Content-Disposition: form-data; name="values"; filename="values.json"
Content-Type: application/json

{
    "firstName": "John",
    "lastName": "Doe",
}
------------------------------330184f75e21
Content-Disposition: form-data; name="icon"; filename="icon.png"
Content-Type: application/octet-stream

imagedata
------------------------------330184f75e21
Content-Disposition: form-data; name="icon@2x"; filename="[email protected]"
Content-Type: application/octet-stream

imagedata

I am not sure what to place in the cURL at all.

I have tried the following without success.

$url1 = 'https://api.passes.com/v1/templates/names/Test/pass';

$data1 = array("values" => '{"first":"John","last":"Doe"}','application/json',
                "strip" => '@../uploads/icon.png','application/octet-string','icon.png',
                "strip@2x" => '@../uploads/icon.png','application/octet-string','icon.png');

$auth1 = array(  "authorization: Basic xxxxxxxxxxxx=",  "cache-control: no-cache",  "postman-token: xxxxxxxxx");

$ch1 = curl_init($url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_POST, 1);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $auth1);

$response1 = curl_exec($ch1);

echo $response1;

It replies with a response saying invalid JSON

If anyone can help that would be great.

Thanks

Rob

1 Answer 1

2

You should not write raw json string, but let PHP do it for you.

$values = array(
    'first' => 'John',
    'last' => 'Doe'
);

$data1 = array(
    'values' => json_encode($values),
    'strip' => '@../uploads/icon.png',
        'application/octet-string',
        'icon.png',
    'strip@2x' => '@../uploads/icon.png',
        'application/octet-string',
        'icon.png'
);
Sign up to request clarification or add additional context in comments.

1 Comment

Ok so it means what you send is valid JSON format but invalid data structure from what they expect.

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.