Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About speckytwat2

  • Rank
  1. Thanks, looking at that though the only problem is the JSON data being pulled from the API is going to be different each time, so I can't see how it would work- how would I throw all the raw JSON data into the objectArray variable? I can put it into a PHP variable and in fact tried creating a JSON file from that, so it would have whatever the queried data was on that occasion: $fp = fopen('result.json', 'w'); fwrite($fp, $result); //Where $result is the data pulled through from the API But I don't think the example script can read a specially created JSON file?
  2. Thanks... unfortunately I tried that: $decoded = json_decode($result, true); and $decoded = json_decode($result); The 1st just outputted "Array" and the 2nd threw an error: "Fatal error: Uncaught Error: Cannot use object of type stdClass as array in..." then "Stack trace: #0 {main} thrown in..." I also tried this: $decoded = json_decode($result, JSON_PRETTY_PRINT); But that still outputs the same data, albeit with Array => instances added. Just need a way to get this somehow exported to a HTML table?
  3. Thanks, I already used json_encode above, should I be using it on $result as well? i.e $resultencoded = json_encode($result); I tried that but it just seems to add slashes in front of the quotation marks? Also tried this: <pre><?php echo json_encode($result JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); ?></pre> and <pre><?php echo json_encode($result JSON_PRETTY_PRINT); ?></pre> But it still gives an unfriendly output, putting lots of instances of \n in place?
  4. Hi, I have a connection set up to an API using a PHP script - the API sends back data in JSON format, and if I capture it and echo it, it displays in extremely unfriendly format on the screen. I've tried to find a way to convert this data into readable format, ideally in a HTML table, but although there are articles on converting manually inputted JSON data into a HTML table using Javascript, I can't find a way to do it from a PHP variable. This is what I have so far: if ($_POST['getcompany']) { $companyname = $_POST['_Name']; $ch = curl_init(); $data_array2 = array( 't
  5. UPDATE - I did some digging around and saw a tiny dropdown arrow under Authenticate in their documentation which reveals a different connection URL- so it looks as if the URL they gave me wasn't correct and it needed to have "authenticate" after it. Anyway it now comes back with an Access Denied message which is obviously a separate issue so I will see if I can get that reset and try again. Thanks for your assistance so far.
  6. I'm authenticating by sending the username and password as follows which I believe is what Creditsafe are asking people to do? $data_array = array( 'username' => "email@example.com", 'password' => "passwordstring" ); $make_call = json_encode($data_array); And then I send it using: curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call); If that isn't correct, how would I send the username and password? Thanks. (I did also try adding the following to authenticate, but that didn't send back anything meaningful either) curl_setopt($ch, CURLOPT_USERPWD, "email@ex
  7. Thanks, well I tried the following based on your suggestions: $ch = curl_init(); $data_array = array( 'username' => "email@example.com", 'password' => "passwordstring" ); $make_call = json_encode($data_array); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "https://connect.sandbox.creditsafe.com/v1"); //Execute the request $result = curl
  8. Just to add, I also tried including this in the CURL array: CURLOPT_POSTFIELDS => $make_call, $make_call being the JSON encoded array of username and password declared earlier: $data_array = array( "username" => $username, "password" => $password ); $make_call = json_encode($data_array);
  9. In the Authentication section near the beginning, here: https://www.creditsafe.com/gb/en/enterprise/integrations/api-documentation.html It shows the sample JSON code for authentication on the right, but doesn't indicate exactly how I would use it or send the request from within a PHP system which is what I'm trying to do. So I put together a script using CURL (the one I posted above) to send what I hoped would be the relevant data, but obviously that isn't working- and they refuse to provide anything more than what's in the documentation.
  10. Unfortunately their documentation doesn't have much that's specific, it is simply "Do this" with some minimal examples, which is why I had to try and patch something together and do a lot of guesswork. Their support people have said they're not going to help so I'm kinda stuck.
  11. I've read the documentation about using CURL to send JSON information to an API, but from what I've read there are various ways of doing this... I've tried various suggested methods- but I haven't been able to get it to work... hence my question.
  12. Thanks. At first I thought it might be ok, although the token string is supposed to be longer than that. Then, I manually changed the password so it should no longer work at all... and it still outputted that string (or one of the same length)- so that appears to be coming from somewhere or something else... but I have absolutely no idea what it is. ??? I also wondered if I needed to use json_encode when giving the username and pw to the API (I put a line for that in the code although I didn't end up using it). That said, I wasn't sure how to use CURL to send that JSON data through...
  13. Hi, I'm trying to connect to CreditSafe's API with supplied username and password using PHP's CURL, unfortunately am having to do everything from scratch as they won't provide any details as to how we are supposed to set the connection up. The idea is that a username and pw are supplied and you then get a "token" which can be used to make further requests for data. The username and pw are given by them in JSON format so I am trying to use these and authenticate against their API. At the moment though I get the following for each of the test variables (see end of this script) I'm outputtin
  14. Thanks, is there a way to do the same thing using mysqli? I will look into PDO but need to fix this first- then I will go and learn PDO as soon as I can.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.