Skip to main content
Dec 12, 2014 5:48 PM UTC
Solved

"Invalid cookie value" when calling REST API leads

I'm trying to get the lead information for the current user in a website, using this REST API: Get Multiple Leads By Filter Type

I have the right authentication token ( I am able to call other entries, i.e. /lead/{id}.json ) but whenever I call the "leads" resource with filterType=cookie&filterValues=xxxxxxxxxxxxxx I get a JSON error response with this value in the message property:
Invalid cookie value 'id:561-HYG-937&token:_mch-marketo.com-1415884534947-30230'
I have encoded the '&' inside the cookie value as %26, and it is reaching the API correctly.  The value stated in the error message matches exactly the value of my _mkto_trk cookie on the 'marketo.com' domain.

Any clue on what I may be doing wrong?
Thanks in advance
Jose
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Accepted solution
Dec 12, 2014 9:39 PM UTC
For future viewers of this thread, I also updated this developer blog post with the example:
http://developers.marketo.com/blog/get-a-visitors-cookie-id-and-then-query-associated-lead-data/

14 replies

Dec 12, 2014 9:30 PM UTC
I am not sure where the error is if you are changing the & to %26.  I justed tested the API, and here is a working code sample in Ruby:

===
Code Sample
===

require 'rest_client'
require 'json'

#Build request URL
#Replace AAA-BBB-CCC with your Marketo instance
marketo_instance = "https://AAA-BBB-CCC.mktorest.com"
endpoint = "/rest/v1/leads.json"
#Replace with your access token
auth_token =  "?access_token=" + "cdf27eff-aca0-48cf-a1ac-576ffec65a84:ab"
#Replace with filter type and values
filter_type_and_values = "&filterType=cookie&filterValues=id:AAA-BBB-CCC%26token:_mch-marketo.com-1418418733122-51548&fields=cookies,email"
request_url = marketo_instance + endpoint + auth_token + filter_type_and_values

#Make request
response = RestClient.get request_url

#Returns Marketo API response
puts response

===
Response
===
{"requestId":"aa00#14a405aa786","result":[{"id":583,"email":"testaccount@gmail.com","cookies":"_mch-marketo.com-1418418733122-51548"}],"success":true}
Translate
Accepted solution
Dec 12, 2014 9:39 PM UTC
For future viewers of this thread, I also updated this developer blog post with the example:
http://developers.marketo.com/blog/get-a-visitors-cookie-id-and-then-query-associated-lead-data/
Translate
Dec 17, 2014 8:15 PM UTC
Thanks Murtza for your prompt response. I'm following just the same steps and cannot get it to work, but I may be doing something wrong.  Will re-trace each step again.

Thanks
Jose 
Translate
Dec 17, 2014 8:32 PM UTC
I'm happy to help debug. Can you post the request url and JSON body that your code generates? 
Translate
Dec 19, 2014 6:39 PM UTC
Hi Murtza
thanks again for your help

By rewriting my code from scratch, I do no longer get the "invalid cookie" error.
Unfortunately, the results collection comes empty 
{"requestId":"a095#14a63cd8d05","result":[],"success":true}
even when I have filled several Marketo forms on the same laptop+browser.

This is the URL I am requesting (HTTP GET from the web server running on IIS):

https://220-bkt-314.mktorest.com/rest/v1/leads.json?access_token=742e72b9-176b-4ae2-9754-63e174cab277%3asj&filterType=cookie&filterValues=id:220-BKT-314%26token:_mch-keynote.com-1417097326740-26128&fields=id,email

Any ideas of what I may be doing wrong?
Thanks again.
Jose


 
Translate
Dec 19, 2014 7:08 PM UTC
You are close! I think you are just missing one thing. Add cookies to the list of fields requested. See change below to your request. 

https://220-bkt-314.mktorest.com/rest/v1/leads.json?access_token=742e72b9-176b-4ae2-9754-63e174cab277%3asj&filterType=cookie&filterValues=id:220-BKT-314%26token:_mch-keynote.com-1417097326740-26128&fields=cookies

Let me know if that works?
Translate
Dec 19, 2014 7:37 PM UTC

Hmm, unfortunately it made no difference :(

Do I have any way of checking, with the Marketo Portal, if that cookie has some information attached?

Thanks!
jose

Translate
Dec 19, 2014 7:49 PM UTC
I would make sure you are querying for a known lead in Marketo (a lead that is associated with an email address). Fill out a form and include an email field. Then query with that cookie value. 

I am not aware of any way to query in the UI with cookie value. I think cookie value is only exposed through API.
Translate
Dec 19, 2014 8:19 PM UTC
I just filled out a form with email and other fields, and when I go to the Lead info (Activity Log) I can see the values have been changed as entered in the form. However, I still get an empty results collection using the _mkto_trk cookie on that domain

May it be a permissions issue? I've created the API role, user and service as described here http://developers.marketo.com/blog/quick-start-guide-for-marketo-rest-api/ 

Thanks
Jose 
Translate
Dec 19, 2014 8:23 PM UTC
Wait - just thought of something.
All the forms I ever filled are hosted on our website, and from the webserver we do a HTTP POST to Marketo.
(that's why we need to implement the auto-fill on our side)

Maybe the cookie on our website domain (xxxxxxxxx.com) is never "making" it into the Marketo databases...
Translate