Buscar clientes
Caso precise de dados específicos de um cliente, como por exemplo, ID, endereço ou data de registro, é possível obtê-los através da nossa API de clientes. Para isso, envie um GET com e-mail do cliente ao endpoint /v1/customers/search e execute a requisição ou, se preferir, utilize um de nossos SDKs abaixo.
<?php
MercadoPagoConfig::setAccessToken("YOUR_ACCESS_TOKEN");
$client = new CustomerClient();
$customer = $client->search(1, 0, ["email" => "[email protected]"]);
?>
import { Customer, MercadoPagoConfig } from '@src/index';
const client = new MercadoPagoConfig({ accessToken: '<ACCESS_TOKEN>' });
const customer = new Customer(client);
customer.search({ options: { email: '<EMAIL>' } }).then(console.log).catch(console.log);
CustomerClient client = new CustomerClient();
Map<String, Object> filters = new HashMap<>();
filters.put("email", "[email protected]");
MPSearchRequest searchRequest =
MPSearchRequest.builder().offset(0).limit(0).filters(filters).build();
client.search(searchRequest);
customers_response = sdk.customer.search(filters: { email: '[email protected]' })
customers = customers_response[:response]
var searchRequest = new SearchRequest
{
Filters = new Dictionary<string, object>
{
["email"] = "[email protected]",
},
};
ResultsResourcesPage<Customer> results = await customerClient.SearchAsync(searchRequest);
IList<Customer> customers = results.Results;
filters = {
"email": "[email protected]"
}
customers_response = sdk.customer().search(filters=filters)
customers = customers_response["response"]
package main
import (
"context"
"fmt"
"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/customer"
)
func main() {
accessToken := "{{ACCESS_TOKEN}}"
cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}
client := customer.NewClient(cfg)
request := customer.SearchRequest{
Filters: map[string]string{
"email": "{{EMAIL}}",
},
}
resource, err := client.Search(context.Background(), request)
if err != nil {
fmt.Println(err)
return
}
for _, v := range resources.Results {
fmt.Println(v)
}
}
curl -X GET \
-H 'Authorization: Bearer ENV_ACCESS_TOKEN' \
'https://api.mercadopago.com/v1/customers/search' \
-d '{
"email": "[email protected]"
}'
A resposta trará o seguinte resultado.
json
{
"paging": {
"limit": 10,
"offset": 0,
"total": 1
},
"results": [
{
"address": {
"id": null,
"street_name": null,
"street_number": null,
"zip_code": null
},
"addresses": [],
"cards": [
{
...
}
],
"date_created": "2017-05-05T00:00:00.000-04:00",
"date_last_updated": "2017-05-05T09:23:25.021-04:00",
"date_registered": null,
"default_address": null,
"default_card": "1493990563105",
"description": null,
"email": "[email protected]",
"first_name": null,
"id": "123456789-jxOV430go9fx2e",
"identification": {
"number": null,
"type": null
},
"last_name": null,
"live_mode": false,
"metadata": {},
"phone": {
"area_code": null,
"number": null
}
}
]
}