How to use HTTP request cookies (building OurGroceries action)

Hi,

I want to write drafts script to allow me to add all the items in a draft to ourgroceries.com.

This requires access to the cookies that are in the http response header.

I can’t work out how to access these from the sign-in response, so that I can send them in the next request.

Any help would be greatly appreciated (and action will be shared in the directory when completed)

Martin

Do you know where they document their API?

They don’t have an official API. I’m using http POST in order to complete the forms.

I have it working fine under node.js, but node gives me access to the cookie that is needed to show I am authenticated for that session.

Okay, I’m not sure how you would get that working for Drafts without some sort of intermediary solution, or manual workaround, but hopefully someone else will have an idea of how you could do it.

The HTTPResponse object does not currently provide access to the response headers. Would be a good addition, I will put it on the list.

4 Likes

Thank you for adding headers to the HTTPResponse in Drafts 25.1.4.

I was able to see all the headers, but strangely not the cookies.

I finally worked out that the server was sending the Set-Cookie header on a 302 response to my request.

It seems that I am not seeing that 302 and the Drafts API is handling that redirect, and only giving the 200 response to Drafts internal second request.

Would it be possible for a “no redirects please” flag to be added to HTTP.request? So that I can extract the cookies from the header and handle the redirect.

I hope the is possible some day.

Thanks for all the great work,

Martin

1 Like

I am a user of the OurGroceries app, so would be interested if you get this integration working. Thanks.

Sadly this isn’t possible without being able to stop the redirect, as I need the cookies from the original header.

Thanks for your response.