Reputation: 43
I am trying to construct the URL that would result from some sample PHP code. The code is:
<?php
$ch = curl_init();
// CONNECT TO API, VERIFY MY API KEY AND PASSWORD AND GET THE LEAD DATA
curl_setopt($ch, CURLOPT_URL,"https://app.kartradev.com/api");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'app_id' => 'AIm863DwsOW',
'api_key' => 'QG9GPLW8G',
'api_password' => 'kdwFAfwrfVS',
'get_lead' => array(
'email' => '[email protected]',
),
)
)
);
I am using FileMaker to make and send the URL. If I send this string with an incorrect password:
https://app.kartra.com/api?app_id=BnFTjKPVdrGO&api_password=eMEaKWSfUQXu&api_key=YnvDR
I get this response indicating that I am successful in querying the API:
{ "message": "API credentials are not valid. Please get an API key and API password first", "status": "Error", "type": "203" }
The array being built by the php code is what is tripping me up. I have tried quite a few variations, for example:
I always get this result:
{ "status": "Error", "message": "'actions' not an array", "type": "224" }
I have requested help from the api tech support people, but this is a brand new API and they have not replied yet (they are rolling out their site by Monday and are very busy).
My question: Given that code above, what would the resulting url look like?
Edited:
Here is the full json response I got with Matt's suggestions on 4/1/18:
Thanks, @MattGibson! I tried your suggestion, got back the same error as before. I also tried tex/plain and application/json. Here is the full JSON response I always get: { "body": "{\"status\":\"Error\",\"message\":\"'actions' not an array\",\"type\":\"224\"}", "code": 200, "headers": { "CF-RAY": 4.054e+96, "Cache-Control": "no-store, no-cache, must-revalidate", "Connection": "keep-alive", "Content-Encoding": "gzip", "Content-Type": "text/html; charset=UTF-8", "Date": "Mon, 02 Apr 2018 17:10:49 GMT", "Expect-CT": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", "Expires": "Thu, 19 Nov 1981 08:52:00 GMT", "Pragma": "no-cache", "Server": "cloudflare", "Set-Cookie": "ci_session=d47fe563bbbe215ab4f936ce1a951e0d28d39d57; expires=Mon, 02-Apr-2018 20:10:49 GMT; Max-Age=10800; path=/; secure; HttpOnly", "Strict-Transport-Security": "max-age=31536000; includeSubDomains", "Transfer-Encoding": "chunked", "Vary": "Accept-Encoding" }, "status": "HTTP/1.1 200 OK" }
Upvotes: 0
Views: 734
Reputation: 38238
The PHP result of that http_build_query
would be:
app_id=AIm863DwsOW&api_key=QG9GPLW8G&api_password=kdwFAfwrfVS&get_lead%5Bemail%5D=JoeSmith%40domain.com
...so the whole URL would be simply
However, given that it's sent as a POST request (CURLOPT_POST = 1
), that's not really what gets sent to the server. In fact, you'd actually hit the base URL https://app.kartradev.com/api
, with your parameters sent in the body of the POST request in application/x-www-form-urlencoded
format.
So to replicate your example code in Filemaker, you'd need to do whatever Filemaker needs to send the request as a POST with the parameters in the appropriate format in the body.
In total, given your PHP code, the result would be an HTTP POST request that looked like this:
POST /api HTTP/1.1
Host: app.kartradev.com
Content-Type: application/x-www-form-urlencoded
app_id=AIm863DwsOW&api_key=QG9GPLW8G&api_password=kdwFAfwrfVS&get_lead%5Bemail%5D=JoeSmith%40domain.com
Upvotes: 0
Reputation: 460
you should add GET-parameters to the query URL, not the POST fields.
curl_setopt($ch, CURLOPT_URL,"https://app.kartradev.com/api?".http_build_query($params));
Upvotes: 0