2

can you please help me with this issue.

I need to connect to json API and authenticate (connectorauth) via two parameters - key and connector_id. Key is the API key, and connector_id is just an id. I also have a url to extract the data from.

All I know is that I have to get the data via post and curl. Can you please send me an example script to authenticate. I'm not sure how to use the two parameters key and connector_id.

Should I use them in header, or I should use CURLOPT_USERPWD.

On success, I should get this result - Image

Thanks

1 Answer 1

2

Try this,

$url will be the post url
$params is query string for eg:- key=somevalue&connector_id=value

$count no of parameters passed. Int this example 2 key and connector_id

function download_page($url, $count, $params) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_FAILONERROR, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);
            curl_setopt($ch, CURLOPT_POST, $count);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            $result = curl_exec($ch);
            curl_close($ch);
            return $result;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it worked. Thanks a lot :) There was also a problem with the SSL, so I needed to add curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.