SOLVED

"Invalid cookie value" when calling REST API leads

Go to solution
Anonymous
Not applicable

"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
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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/

View solution in original post

14 REPLIES 14
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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}
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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/
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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 
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

I'm happy to help debug. Can you post the request url and JSON body that your code generates? 
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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


 
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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?
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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

Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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.
Anonymous
Not applicable

Re: "Invalid cookie value" when calling REST API leads

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