- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everyone,
I am really struggling with converting what I am able to get to run in Postman, into a valid Proc HTTP statement...
I usually am able translate the cURL code snippets from Postman into SAS using Proc HTTP quite easily, but this one is stumping me.
Here is the cURL code that works(removed my secret code and Postman token)...
curl -X GET \
'https://mixpanel.com/api/2.0/jql?script={{encoded_script}}' \
-H 'Authorization: Basic <my Secret Code>' \
-H 'Postman-Token: My Token' \
-H 'cache-control: no-cache'
The {{encoded_script}} is a prerequest script that URLEncodes the actual script...
var encoded = encodeURIComponent(function main() {return Events({from_date: "2018-10-17", to_date: "2018-10-19"})});
postman.setEnvironmentVariable("encoded_script", encoded);
In reading the 3rd party vendors API documentation(JQL is what they use), here is a cURL example they give...
curl https://mixpanel.com/api/2.0/jql \ -u Secret_Code \ --data-urlencode params='{"from_date":"2016-01-01", "to_date": "2016-01-07"}' \ --data-urlencode script='function main(){ return Events(params).groupBy(["name"], mixpanel.reducer.count()) }'
My Proc HTTP statement looks like this, where the script= part has been run through the URLEncode function(I tried it not running it through that as well)...
proc http
method="GET"
url="https://mixpanel.com/api/2.0/jql?script='%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%2...'"
ct="application/json"
headerout=hresult
out=json;
headers "Authorization" = "Basic &api_secret.";
run;
It authenticates fine but I always get a Bad Request with a message similar to ...
{"request": "/api/2.0/jql?script=%27function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%222018-10-17%22%2C%20to_date%3A%20%222018-10-19%22%7D)%7D%27", "error": "[Validate failed]the query must define the main() function\n"}
I have also tried putting the script= into the IN= statement but the API always tells me I am missing the Script= statment(which is required).
It seems to have something to do with URL Encoding the script, but it still doesn't seem like it likes my URL Encoded text.
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I am very close to getting this working. If I remove the single quotes around the URL Encoded script= code, it WORKS(See below)!
proc http
method="GET"
url="https://mixpanel.com/api/2.0/jql?script=function%20main()%20%7Breturn%20Events(%7Bfrom_date%3A%20%22..."
ct="application/json"
headerout=hresult
out=json;
headers "Authorization" = "Basic &api_secret.";
run;
The issue was the script = code does NOT need the single quotes(even though the cURL statement shows them).
However, this now presents another problem. I need to put the script code into its own file and then call the file. The problem is, when I put the file name as the script= statement(something like script=jscript.js), JQL thinks the jscript.js the actual script code and not a file name.
I guess I can set a macro variable to the entire file and then just drop the macro variable in place of the jscript.js filename but that seems a little odd to have to do.
Any thoughts on this one?
Thanks.