Json POST con PHP
Publicado por Luis (1 intervención) el 30/09/2016 11:15:27
Buenos días,
Pretendo insertar datos via API en Acumbamail y no consigo que cURL funcione. Ahí va el código.
Gracias!!!
Pretendo insertar datos via API en Acumbamail y no consigo que cURL funcione. Ahí va el código.
Gracias!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
//API Url
$url = 'https://acumbamail.com/api/1/addSubscriber';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'constumer_id' => 'sssa',
'auth_token' => 'sdsss',
'list_id' => 'dsafa',
'merge_fields[email]' => 'prueba@gmail.com'
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
curl_exec($ch);
Valora esta pregunta


0