Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.darksci.pardot.api.InvalidRequestException #45

Closed
tfranchiDD opened this issue Feb 17, 2020 · 8 comments
Closed

com.darksci.pardot.api.InvalidRequestException #45

tfranchiDD opened this issue Feb 17, 2020 · 8 comments

Comments

@tfranchiDD
Copy link

Hi,

when we call this method with a prospect that not exists in Pardot (email):
pardot.prospectRead(request);

we retrieve this error:
com.darksci.pardot.api.InvalidRequestException: Invalid API key or user key

How we could check if a prospect exists in Pardot without errors?

@Crim
Copy link
Owner

Crim commented Feb 17, 2020

That error indicates that your Pardot API credentials are being rejected by Pardot's API servers.
Authentication Documentation

Make sure you've supplied correct credentials.

@tfranchiDD
Copy link
Author

It is not correct because after the read we make the creation and the creation works correctly while the read gives that error.

Below an example of our code:

ProspectReadRequest request = new  ProspectReadRequest ();
request.selectByEmail(contactSf.getEmail());

Prospect resultProspect = null;

try {
	resultProspect = pardot.prospectRead(request);
}
catch (InvalidRequestException e) {
	log.warning("InvalidRequestException: {0} - {1}", String.valueOf(e.getCause()), String.valueOf(e.getMessage()));
}

if (resultProspect == null) {

	ProspectCreateRequest prospectCreate = new ProspectCreateRequest ();

	Prospect prospect = new Prospect ();
	prospect.setEmail(contactSf.getEmail());
	prospect.setPhone(contactSf.getMobilePhone());
	prospect.setFirstName(contactSf.getFirstName());
	prospect.setLastName(contactSf.getLastName());
	prospect.setCampaignId(this.getCampaignId());

	prospectCreate.withProspect(prospect);

	try {
		resultProspect = pardot.prospectCreate(prospectCreate);
	}
	catch (InvalidRequestException e) {

		log.warning("InvalidRequestException: {0} - {1}", String.valueOf(e.getCause()), String.valueOf(e.getMessage()));
		
	}
}

@Crim
Copy link
Owner

Crim commented Feb 18, 2020

Running the following to query a prospect which does not exist:

final Prospect response = client.prospectRead(new ProspectReadRequest()
     .selectByEmail("does-not-exist@example.com")
);

for me throws the following:

INFO  | 2020-02-18 18:34:36 | [main] api.PardotClient (PardotClient.java:223) - Response: RestResponse{responseStr='<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="fail" version="1.0">
   <err code="4">Invalid prospect email address</err>
</rsp>
', httpCode=200}

com.darksci.pardot.api.InvalidRequestException: Invalid prospect email address

	at com.darksci.pardot.api.PardotClient.submitRequest(PardotClient.java:240)
	at com.darksci.pardot.api.PardotClient.prospectRead(PardotClient.java:754)

Which unfortunately is just how the library works at the moment. Likely some work could/should be put in to make error results from the API handled in a better way.

Do you see the same error (Invalid prospect email address) or are you seeing Invalid API key or user key?

@tfranchiDD
Copy link
Author

I have run your code in main class and I have this error:

com.darksci.pardot.api.InvalidRequestException: Invalid http response code from server: 400

but In debug mode I have check the correct response inside library:

RestResponse{responseStr='

Invalid prospect email address

', httpCode=400}

but in library code there is this:

throw new InvalidRequestException("Invalid http response code from server: " + restResponse.getHttpCode(), restResponse.getHttpCode());

@tfranchiDD
Copy link
Author

Could the session have timed out ???

After restarting the server, I haven't had this error for a short time.

@Crim
Copy link
Owner

Crim commented Feb 20, 2020

Ah that's possible. I'll try to mock up a test and verify the behavior. I thought that the library should automatically re-authenticate and replay the request that failed on session timeout, but there could be a bug there.

Will report back.

@Crim
Copy link
Owner

Crim commented Feb 20, 2020

Posted a bugfix for the session renewal issue you brought up, thanks for reporting it!

I'll release and publish a new version (1.1.2) shortly.

@Crim
Copy link
Owner

Crim commented Feb 20, 2020

Published version 1.1.2 with the fix for this.

I'm going to close this issue, but if you continue to have problems, or run into other issues please submit an issue and I can help get it resolved.

Thanks!
Stephen

@Crim Crim closed this as completed Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants