How to send parameter in array using Curl in php

Asked

Viewed 77 times

0

I am integrating an API that imports immovable information using Curl in PHP.

I stopped to import the photos, in the documentation he says:

QUERY PARAMETERS
dimensions

Array of strings
Items Enum: "200x140" "520x280" "1024x1024"
Example: dimensions=200x140,1024x1024

I tried it the way below, but I don’t know how to send the parameter Dimensions=200x140:

$headers = array(
    'Content-Type: application/json',
    sprintf('Authorization: Bearer %s', $result->access_token)
);
$curl = curl_init("https://www.linkapi.com.br/api/v2/buildings/7034/images");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$fotos = json_decode(curl_exec($curl));
var_dump($fotos);

$result->access_token is the token received in the previous request

In this above, it returns: Invalid parameters: Dimensions. Check out the documentation and adjustment

But all the documentation says is what I wrote on top.

1 answer

0

According to the documentation, is a "QUERY PARAMETERS". I believe this referred to query strings that are part of the URL.

Then just do:

$query_param = "dimensions=200x140,1024x1024"

$curl = curl_init("https://www.linkapi.com.br/api/v2/buildings/7034/images?" . $query_param);

You can also use the http_build_query with the PHP_QUERY_RFC3986 if you prefer something more elegant.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.