Is anyone successfully using the CJ web services? I just keep getting java.lang.NullPointerExceptions even though my app is .net (clearly their errors). CJ support doesn't even know what a web service is. I googled and found many people getting this or other errors. Question is: is it a temporary problem or am I doomed to parse manually downloaded reports for eternity?
The specific API I'm trying to use is the daily publisher commission service. Here is the WSDL.
Links:
CJ web services home
API Reference
After a spending many days, this code is working for me.
$client = new SoapClient($cjCommissionUrl,
array('trace' => 1,
'soap_version' => SOAP_1_1,
'style' => SOAP_DOCUMENT,
'encoding' => SOAP_LITERAL
));
$date = '06/23/2010';
$results = $client->findPublisherCommissions(array(
"developerKey" => $cjDeveloperKey,
"date" => $date,
"dateType" => 'posting',
"countries" => 'all',
));
I have successfully used CJ's API with PHP, though not this particular WSDL. I am seriously troubled by the lack of documentation and even cannot find any serious programmer using it (all amateurs basically trying to copy-paste). If you have some more experience we may be able to help each other out.
I had written a Python library for retrieving commission info from CJ. Here is the code: https://github.com/sidchilling/commissionjunction-python-lib
Works for me.
create a page cjcall.php forexample
paste this code and do according to your requirement i.e. keyword , dev id , records per page
include('../../../../wp-load.php');
$stringkeyw=urlencode(get_option('cj_keyword'));
if(get_option('rm_num_products')==''){
$pperkeyword=50;
}else{
$pperkeyword= get_option('rm_num_products');
}//number of products against keyword
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://product-search.api.cj.com/v2/product-search?website-id=".get_option('cj_siteid')."&keywords=".$stringkeyw."&records-per-page=".$pperkeyword."&serviceable-area=US");
curl_setopt($ch, CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:".get_option('cj_devid').""));
$result = curl_exec($ch);
create another page and paste the following code to bring xml from this page:
$hurl= home_url();
$homepage = file_get_contents(''.$hurl.'/wp-content/plugins/rapid_monetizer/cronjob/cjcall.php');
$object = simplexml_load_string($homepage);
foreach($object->products->product as $cjres)
{
//do your code with products coming in $cjres
}
I can make a user interface for you to lift your curse !!!
To use Daily Publisher Commission Report Service !!
Let me know here if you still need help.
EDIT: First and foremost, you will not get any results back if there are no commissions to report.
I am working with these API's, I have no problem with any of the REST API's, the SOAP API for the daily publisher commission service does not appear to be working. The results from:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="https://pubcommission.api.cj.com">
<soapenv:Header/>
<soapenv:Body>
<api:findPublisherCommissions>
<api:developerKey>*DEVKEY*</api:developerKey>
<api:date>01/19/2007</api:date>
<api:dateType>event</api:dateType>
<api:advertiserIds></api:advertiserIds>
<api:websiteIds>123456</api:websiteIds>
<api:actionStatus>all</api:actionStatus>
<api:actionTypes></api:actionTypes>
<api:adIds></api:adIds>
<api:countries></api:countries>
<api:correctionStatus></api:correctionStatus>
<api:sortBy>commissionAmount</api:sortBy>
<api:sortOrder>desc</api:sortOrder>
</api:findPublisherCommissions>
</soapenv:Body>
</soapenv:Envelope>
Which is completely valid and correct, gives me an HTML page back. Your error is probably related to parsing the page as XML.
The results are:
<html>
<head>
<title>Web Services</title>
</head>
<body vlink="#333333" alink="#FFCC33" bgcolor="#FFFFFF" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td background="images/header_bg.gif">
<img src="images/header.gif" width="600" height="63" border="0" alt="webservices.cj.com" />
</td>
</tr>
</table>
<h3>Latest WSDLs</h3>
<table width=70%><tr><td>
<ul>
<li>ProductSearchServiceV2.0[wsdl]<img src="images/new11.gif" width="40" height="15"/></li>
<li>LinkSearchServiceV2.0[wsdl]<img src="images/new11.gif" width="40" height="15"/></</li>
<li>PublisherCommissionService and ItemDetails V2.0[wsdl]<img src="images/new11.gif" width="40" height="15"/></</li>
<li>RealTimeCommissionServiceV2.0[wsdl]<img src="images/new11.gif" width="40" height="15"/></</li>
<li>AdvertiserSearchService[wsdl]</li>
<li>FieldTypesSupportService[wsdl]</li>
</ul>
</td></tr></table>
<h3>Previously Released WSDLs</h3>
For previous versions of the wsdls click here.<p>
<h3>Sign Up</h3>
<ul>
<li>Sign Up</li>
</ul>
</body>
</html>
I have sent them an email, and expect a response today. I will confirm with you that this API is still available, it may have been completely replaced by the Real Time publisher commission API.
Related
I am planning to use Google invisible Recaptcha V3 in my application. I want the suggestion by which method I can go. In the developer document, I could see 2 ways,
Automatically bind the challenge to a button (https://developers.google.com/recaptcha/docs/v3)
Programmatically invoke the challenge
for the 2nd option, I know we are doing the server-side validation to check the token from my site and we are getting the scores.
I want to know if I am going to use the 1st option, and how it gets validated from the ReCaptcha server.
If you want to use the 1st option, you just include a submit button inside your form, and you will receive the reCaptcha token in the 'g-recaptcha-response' key from the POST field (e.g.: $_POST['g-recaptcha-response'], if you're using php).
<script src="https://www.google.com/recaptcha/api.js"></script>
<form method="post" action="login" id="loginForm">
<label for="password">Password:</label>
<input type="password" name="password" value="">
<!--Recaptcha button-->
<button class="g-recaptcha"
data-sitekey="#your_site_key"
data-callback='onSubmit'
data-action='submit'>Submit</button>
</form>
<script>
function onSubmit(token)
{
document.getElementById("loginForm").submit();
}
</script>
Then, validate the token submiting it to "https://www.google.com/recaptcha/api/siteverify" as you would do with the 2nd option.
If you are on php, login page from the form's action attribute, would look like this:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query([
"secret"=>"#yourSecretKey"
, "response"=>$_POST['g-recaptcha-response']
, "remoteip"=>$_SERVER['REMOTE_ADDR']
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$recaptcha = json_decode(curl_exec($ch), true);
/** $recaptcha:
Array
(
[success] => 1 // or 0
[challenge_ts] => 2022-07-16T12:34:38Z
[hostname] => host // hostname
[score] => 0.9 // 0.0 to 1.0
[action] => submit // data-action attribute from reCaptcha button
)
*/
if ($recaptcha["score"] >= 0.5 && $recaptcha["action"] === 'submit')
{
// action on success
} else {
// action on false
}
?>
About which one to use, I don't know how to answer that... But I guess that both options work similarly, so go with the one that is easier for you to implement.
I need to call Shopify's API's to create a new product or get details of existing products. How can i do this. Basically how to make a connection of salesforce with shopify?
Shopify provide REST API, so you need to use it for integration with your Salesforce solution. On Salesforce side you need to do few steps for implementation of connection.
Usual you need to make a post/get requests to some URL you would do the following.
Add your domain under Remote Site Settings
To send an outbound calls (POST/GET requests) from Apex in Salesforce, you need to add the domain to Remote Site Settings in setup.
Create and send the request in your APEX controller
For instance, for POST request you need to implement something like this
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://someurl.com/api');
req.setMethod('POST');
//these parts of the POST you may want to customize
req.setCompressed(false);
req.setBody('key1=value1&key2=value2');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
try {
res = http.send(req);
} catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
}
System.debug(res.getBody());
For more information take a look on Salesforce documentation:
Apex Web Services and Callouts
HttpRequest Class
HttpResponse Class
I just recently actually managed to develop what (I think) you are looking for in PHP and since i had plenty trouble finding all the info I actually went ahead and created an account just to answer this for you :)
my PHP code is as follows:
//Modify these
$API_KEY = 'yourAPIkey';
$SECRET = 'yourAPIsercer(password)';
$TOKEN = 'zzz';
$STORE_URL = 'yourstore.myshopify.com';
$url = 'https://' . $API_KEY . ':' . $SECRET . '#' . $STORE_URL . '/admin/products.xml';
$xmlsrc = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<product>
<title>TITLEH!!!</title>
<body-html>asdasdfda</body-html>
<product-type>Photoshop</product-type>
<variants type="array">
<variant>
<price>3.00</price>
<inventory-quantity>7</inventory-quantity>
</variant>
</variants>
<vendor>JLH</vendor>
</product>
XML;
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($session, CURLOPT_POSTFIELDS, $xmlsrc);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if(ereg("^(https)",$url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);
$result = curl_exec($session);
curl_close($session);
$doc = new DOMDocument();
$doc->preserveWhiteSpace = true;
$doc->formatOutput = true;
$doc->loadXML($result);
echo $doc->saveXML();
I believe it's straightforward enough.
It's also quite easy to modify it for different actions once you get the hang of it...
I got alot of useful info from this thread: https://ecommerce.shopify.com/c/shopify-discussion/t/php-api-example-26017
and the rest i deducted from the shopify API reference: https://help.shopify.com/api/reference/product
(note that API reference uses json examples and i am working with XML)
I hope this helps you.
I have an issue when trying to generate Access Token by POST data to https://login.bigcommerce.com/oauth2/token. There is an exception error ('The remote server returned an error: (400) Bad Request.'). I don't know why but I already read the document at https://developer.bigcommerce.com/apps/callback#token
If I open that URL on any web browsers. It said that "The page you were looking for doesn't exist."
Could you please help me this?
Thank you,
Trung
If you are getting a 400 response to your POST request to https://login.bigcommerce.com/oauth2/token then that is indicating a problem with your data. The most likely causes are:
You are not including the following header in your POST request:
Content-Type: application/x-www-form-urlencoded
You are not URL encoding your POST data such as the following example:
client_id=236754&client_secret=m1ng83993rsq3yxg&code=qr6h3thvbvag2ffq&scope=store_v2_orders&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fapp.example.com%2Foauth%26context%3Dstores%2Fg5cd38&context=stores%2Fabc123
Also note that the error response message body that you receive should have some more details about the source of the problem.
If you have confirmed the above points then maybe try giving a sample of your POST data or some information about what you are doing to URL encode your data. Make sure not to include your actual client ID, client secret, or redirect URI.
Try ussing cURL
$data = array( "client_id" => "sdfgdfgdfkxddfgdfgdfdfgdfgddfgdfg2",
"client_secret" => "sdfgsdfgsdfgsdfgsdfgdf",
"redirect_uri" => "https://youapp.com/oauth",
"grant_type" => "authorization_code",
"code" => $_GET["code"], "scope" => $_REQUEST["scope"], "context" => $_GET["context"], );
$postfields = http_build_query($data);
$ch = curl_init();
$url = "https://login.bigcommerce.com/oauth2/token";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$obj = json_decode($output);
var_dump($obj);
Firstly you need to get temporary authorization code, but sending GET request to https://login.bigcommerce.com/oauth2/authorize with parameters clientId, Scope, Context ("stores/{your_store_hash}") and redirect_url.
Only after this, you can change your temporary token to permanent token (see previous post).
This permanent token expires in 30-60 days, but I don't know how to renew it automatically without user action. If you know that, please write how.
I would like to get content (posts) from a google+ page and post it to my website, as a feed. Is there any info how?
I read that current API does not allow that, but those topics were from the last year.
Thanks.
You can perform activities.list, without having to authenticate, by passing your "simple" key from the API console for a project created that has the Google+ service turned on. Access to the API calls is restricted to the authorized origins you set up in your project.
After you create the project, in the section "Simple API Access" there is an API key. Build your client with this key, your client id, and client secret:
<?
$client = new Google_Client();
$client->setDeveloperKey("YOUR_API_KEY");
$plus = new Google_PlusService($client);
$activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>
<html><body><pre><? echo print_r($activities);?></pre></body></html>
A final note, make sure you use the latest Google+ PHP client.
After some time I found it.
http://code.google.com/p/google-plus-php-starter/
and this
https://developers.google.com/+/api/latest/activities/list
The only problem is that you need to log into your google app to do this. Any sugggestions would be apprecited.
Updating the correct answer, the class name has changed to Google_Service_Plus
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
require_once __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->setDeveloperKey("YOUR_API_KEY");
$plus = new Google_Service_Plus($client);
$activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>
$items = $activities->getItems();
foreach($items as $item) {
$object = $item->getObject();
?>
<div class="gpost">
<p><?php echo $object->getContent(); ?></p>
Read more
</div>
<?php } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calling a Web Service Using XmlHttpRequest</title>
<script type="text/javascript" language="javascript">
var xmlhttp;
var XMLContent='<XML ID="Transaction"><Transaction>'+
'<LoginDetails>'+
'<Email>artur</Email>'+
'<Password>demos2</Password>'+
'</LoginDetails>'+
'<JobDetails>'+
'<JobId>40170978</JobId>'+
'<JobRefNo>prod84</JobRefNo>'+
'<JobTitle>'+
'<![CDATA[ Director of R&D Software product (Multimedia)]]>'+
'</JobTitle>'+
'<JobExpiry>30</JobExpiry>'+
'<JobContactName>'+
'<![CDATA[ Brian Mc Fadden]]>'+
'</JobContactName>'+
'<JobContactEmail>brian.mcfadden#recruiters.ie</JobContactEmail>'+
'<JobShortDesc>'+
'<![CDATA[ Director of R&D Software product concepts Multimedia Web 2.0]]> '+
'</JobShortDesc>'+
'<JobDetDesc><![CDATA[ <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><STRONG>Director of R&D Software product concepts to</STRONG> build a the new prototyping team and processes from the ground up, utilizing an agile development model, manage the R&D team develop a strong vision and be able to clearly articulate the direction the group will take in terms of methodologies and tools in technologies such as J2EE, .NET, Flash, AJAX, DHTML, JavaScript, take marketing requirements from the principal investigators and write functional requirement documents, manage budget for R&D development, manage the projects developed by the internal team and vendors. </P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">To get this new role you will have a degree in IT / Software and over 5 years plus doing cutting edge development in R&D/ prototyping and leading cutting edge development teams in a software production / product environment, project management and process management skills (AGILE) and demonstrated experience working on product innovation and releases. You may be working in educational gaming, social networking, Web 2.0 applications, mobile technologies, learning management systems, online courseware or shareware. </P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"> </P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">The package is to €105K + Bonus + VHI + Pension + relocation package where applicable + stock options may be negotiated. There are great career advancement opportunities. To discuss this and other opportunities please send an up-to-date resume to brian.mcfadden#recruiters.ie or call +353 1 6489113 in confidence. Your details will not be sent to any third party without your consent. </P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"> </P>]]>'+
'</JobDetDesc>'+
'<JobSalary>90000</JobSalary>'+
'<JobSalaryMax>105000</JobSalaryMax>'+
'<JobQues1><![CDATA[ ]]>'+
'</JobQues1>'+
'<JobQues2><![CDATA[ ]]>'+
'</JobQues2>'+
'<JobQues3><![CDATA[ ]]>'+
'</JobQues3>'+
'<JobType>0|0</JobType>'+
'<JobAddnlBens>17,14,23,1,5,9,12,10</JobAddnlBens>'+
'<JobLocations>96,98,97</JobLocations>'+
'<JobEducations>8</JobEducations>'+
'<JobExperiences>10</JobExperiences>'+
'<JobCategories>1043,1050</JobCategories>'+
'<JobSubcategories>69896,69869</JobSubcategories>'+
'</JobDetails>'+
'</Transaction>'+
'</XML>';
function on_click()
{
if(window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (ex)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
}
else if (window.XMLHttpRequest)
{
xmlhttp = new window.XMLHttpRequest();
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
}
var xmlToSend = '<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
'<soap:Body>'+
'<InsertXML xmlns="http://recpushdata.cyndigo.com/">'+
'<Jobs>'+XMLContent+'</Jobs>'+
'</InsertXML>'+
'</soap:Body>'+
'</soap:Envelope>';
var szUrl;
szUrl = 'http://recpushdata.cyndigo.com/Jobs.asmx?op=InsertXML';
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open("Post", szUrl, true);
xmlhttp.setRequestHeader ("SOAPAction", "http://recpushdata.cyndigo.com/InsertXML");
xmlhttp.setRequestHeader ("Content-Type", "text/xml");
xmlhttp.send(xmlToSend);
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
alert("OK"+xmlhttp.responseText);
}
else
{
alert("Problem retrieving XML data "+xmlhttp.responseText);
}
}
}
</script>
</head>
<body>
<div>
<h1>
Click the button to call the web service</h1>
<input type="button" onclick="return on_click();" value="OK" />
</div>
<div id="responseDiv">
</div>
</body>
</html>
XmlHttpRequest can only be used to call services local to the domain/server from where the page is being served.
Thus, if you're serving a page from:
http://www.example.com/page1
You cannot make an XmlHttpRequest to:
http://www.sample.com/webservice
Since you're setting Content-type, you need to also set it to use UTF-8. And I think it's supposed to be application/xml (source).
xmlhttp.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
Otherwise, have you verified that the XML is properly formatted? Try saving it as a complete XML file and open it in your browser.
For Internet Explorer
http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/
For Firefox
http://installingcats.com/2008/01/29/how-to-fix-ajax-error-uncaught-exception-permission-denied-to-call-method-xmlhttprequestopen/