JSON request returning "Access token not specified"

Anonymous
Not applicable

JSON request returning "Access token not specified"

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Text" %>
<%@ Import Namespace="System.Web.UI.Page" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">

    
    
    Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
        Dim req As WebRequest = WebRequest.Create(uri)
        req.ContentType = contentType
        req.Method = method
        req.ContentLength = jsonDataBytes.Length


        Dim stream = req.GetRequestStream()
        stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
        stream.Close()

        Dim response = req.GetResponse().GetResponseStream()

        Dim reader As New StreamReader(response)
        Dim res = reader.ReadToEnd()
        reader.Close()
        response.Close()

        lblCookie.Text = res
        Return res
    End Function
    Sub Page_Load()
        Dim MKTOcookie As String
        If Not Request.Cookies("_mkto_trk") Is Nothing Then
            MKTOcookie = Request.Cookies("_mkto_trk").Value
        End If

        Dim uri As New Uri("https://XXX-YXD-XXX.mktorest.com/rest/v1/leads.json?")

        Dim accesstkn = "03e39e6a-d902-4f33-XX-XXXXX:XX"
        Dim cookieid = Server.UrlEncode(MKTOcookie)
        Dim fieldsrtn = "email,firstName,lastName,company"
        
        Dim data = Encoding.UTF8.GetBytes("access_token=" + accesstkn + "&filterType=cookie&filterValues=" + cookieid + "&fields" + fieldsrtn)
        Dim result_post = SendRequest(uri, data, "application/json", "POST")
   
    End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<asp:Label ID="lblCookie" runat="server"></asp:Label>
</form>
</body>
</html>

 
Tags (1)
1 REPLY 1
Anonymous
Not applicable

Re: JSON request returning "Access token not specified"

I am guesssing the access token is not being passed as a parameter. Check out the Ruby sample code on the dev docs for this API to see how request should look.