Try 30 days of free premium.

Filemaker Authorisation

lycanthrope7 wrote 5 years ago: 1

Hi guys,

I'm finally taking the plunge and trying to learn the user API. I've been through the documentation and tried out some of the API calls. I just have one question... How do I obtain the authorisation code?

In the curl commands returned by the documentation page, there a bit that says, "--header 'Authorization: Basic", followed by a long string of letters and numbers, which I'm assuming is the authorisation code returned by sending your user name and API key to the appropriate URL. I'm trying to figure out how to get that code from within my app.

I've tried sending my user name and password using the curl --user lycanthrope7:myAPIkey to the url http://api.tvmaze.com/ as well as http://api.tvmaze.com/v1/user/ but I just got back "{"name":"Not Found","message":"Page not found.","code":0,"status":404,"previous":{"name":"Invalid Route","message":"Unable to resolve the request \"v1/user/\".","code":0}}"

I must be doing something wrong, but there's not enough info in the documentation for me to figure it out. Please help!

Technical info: I'm using a FileMaker Pro database to retrieve info about shows that I watch and keep track of episodes I've downloaded, watched etc. It does a bunch of other stuff too, but that's irrelevant. For information about how FileMaker retrieves info from API's go here. For info about the curl options it supports, go here.

lycanthrope7 wrote 5 years ago: 1

Hi David,

Thanks for your reply. The problem is I don't know how to authenticate. I tried sending --user lycanthrope7:myAPIkey to the URL you specified and got the following:

{"name":"Internal Server Error","message":"An internal server error occurred.","code":0,"status":500}


david wrote 5 years ago: 1

Curl should handle the --user lycanthrope7:myAPIkey parameter fine though.

lycanthrope7 wrote 5 years ago: 1

david wrote:
I actually suspect that you're hitting another bug and the error is not related to the authentication. While I check this out, could you try with a different endpoint e.g. https://api.tvmaze.com/v1/user/follows/shows?

It worked! I got back a list of the 419 shows that I follow. So there's a bug with the other endpoint then? I never thought to try another one because all I want to do is mark episodes as acquired/watched.


david wrote 5 years ago: 1

Could you try again now?

lycanthrope7 wrote 5 years ago: 1

david wrote:
Could you try again now?

Authentication seems to be working. When I just send my --user details I get back {"name":"Not Found","message":"","code":0,"status":404}.

If I send the full string to mark the episode as watched, I get this: {"name":"Unprocessable entity","message":"","code":0,"status":422}

The string I'm sending is: curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic' --user lycanthrope7:apikey -d '{"episode_id":0,"marked_at":0,"type":0}' 'https://api.tvmaze.com/user/episodes/1414931'


FHFbVB1Mkd3 wrote 5 years ago: 1

-d '{"episode_id": 1414931 ,"marked_at":0,"type":0}'

You need to put the episode ID in the data too.


david wrote 5 years ago: 1

lycanthrope7 wrote:
Authentication seems to be working. When I just send my --user details I get back {"name":"Not Found","message":"","code":0,"status":404}.

If I send the full string to mark the episode as watched, I get this: {"name":"Unprocessable entity","message":"","code":0,"status":422}

The string I'm sending is: curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic' --user lycanthrope7:apikey -d '{"episode_id":0,"marked_at":0,"type":0}' 'https://api.tvmaze.com/user/episodes/1414931'

Looks like it should work at first sight; this works fine for me:

curl -X PUT -H "Content-Type: application/json" -d '{"type":1}' https://david:apikey@api.tvmaze.com/v1/user/episodes/1

If that doesn't work for you, perhaps try it in Swagger at https://static.tvmaze.com/apidoc/?

@FHFbVB1Mkd3 The episode_id property isn't actually writeable at all through the body; we only look at the URL path.

lycanthrope7 wrote 5 years ago: 1

david wrote:
Looks like it should work at first sight; this works fine for me:

curl -X PUT -H "Content-Type: application/json" -d '{"type":1}' https://david:apikey@api.tvmaze.com/v1/user/episodes/1

If that doesn't work for you, perhaps try it in Swagger at https://static.tvmaze.com/apidoc/?

@FHFbVB1Mkd3 The episode_id property isn't actually writeable at all through the body; we only look at the URL path.

I tried sending the user name and api key in the URL as you suggested, but got an authorisation error. I have no idea what "try it in Swagger" means, but I went to the link you provided and it just took me back to the user API documentation page, which is where I got the curl code from in the first place. It works fine there, it always has, which is why I'm getting so frustrated that I can't get it working in my database.

I am getting a different error now, which is progress I suppose. I've refined my curl options to this : curl -X PUT -H 'Content-Type: application/json' -u lycanthrope7:apikey -d '{"type":0}' 'https://api.tvmaze.com/v1/user/episodes/1414931'

And the response is {"name":"Unprocessable entity","message":"","code":0,"errors":{"type":["Type cannot be blank."]},"status":422}


FHFbVB1Mkd3 wrote 5 years ago: 1

In just regular terminal with curl that works fine. The error suggest that your JSON data is wrong. I am guessing this is specific from your FileMaker program. In the docs you provided it says:

Notes

Within cURL options, precede each quotation mark with a backslash. For example, to specify an HTTP header for Content-type: application/json, the text expression for Specify cURL options is: "--header \"Content-type: application/json\""

So you should try some backslashes before the double quotes (single quotes is probably no problem), so start with changing the data parameter to: ......-d '{\"type\":0}'.......

lycanthrope7 wrote 5 years ago: 1

FHFbVB1Mkd3 wrote:
In just regular terminal with curl that works fine. The error suggest that your JSON data is wrong. I am guessing this is specific from your FileMaker program. In the docs you provided it says:

So you should try some backslashes before the double quotes (single quotes is probably no problem), so start with changing the data parameter to: ......-d '{\"type\":0}'.......

I actually do have the backslashes in there, but unless you know FileMaker Pro, they'd only confuse you. The actual function looks more like this:

Insert from URL [Select; With dialog:Off; TV Tracker::cURL Result; "https://api.tvmaze.com/v1/user/episodes/1414931"; cURL options: "-X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Basic' -u lycanthrope7:apikey -d {\"episode_id\":0,\"marked_at\":0,\"type\":0}"; Do not automatically encode URL]


FHFbVB1Mkd3 wrote 5 years ago: 1

Okay, so maybe you are missing the single quotes around the data then? -d '{\"marked_at\":0,\"type\":0}'

I indeed don't know anything about FileMaker :p but that latest error really suggest a problem in the data parameter (or missing JSON header - but that looks fine.)

lycanthrope7 wrote 5 years ago: 1

According to the cURL documentation, single quotes are optional when the data doesn't contain any spaces, and may in fact cause an error under Windows. So I took them out to see if it made a difference, but they've been in there every other time I tried. I just put them back in and tried again - same result. I appreciate your help though. Having used FileMaker for some 15 years now, I can tend to get a bit complacent at times, so it helps to have someone who hasn't developed my bad habits take a look at my code.


david wrote 5 years ago: 1

I'm pretty sure the issue is not on our end, but I don't know how to help you any further. I would suggest first getting a a specific URL/command to work in regular (terminal) curl, and then trying to get it working within Filemaker.

lycanthrope7 wrote 5 years ago: 1

Ok, now I'm even more confused. I just accidentally tried to mark an episode that I'd already marked as watched and got back the message:

{"episode_id":1414931,"type":0,"marked_at":1529144263}

I got excited until I realised what I'd done. So I did nothing more than change the episode number to 1462537, and it went back to the error {"name":"Unprocessable entity","message":"","code":0,"errors":{"type":["Type cannot be blank."]},"status":422}.

I've been at this for a week now and I'm about ready to lose my mind.


david wrote 5 years ago: 1

I can explain that one. In REST, a PUT request means that if the requested resource (in this case: the marking of that specific episode) already exists, it's updated with the values you supply.

So if you're sending a request for an episode that you've already marked (as watched, acquired, or skipped), it's technically valid to completely omit the request body. Since you're not sending any values to update, all existing values will remain and the request will have no effect, but you'll still receive a HTTP 200 success code.

If you're sending a request for an episode that you've not yet marked, there are no existing values so you must include them in the request body. If you don't, you'll receive the HTTP 422 error code you pasted.

So what's happening is that in both cases, you (Filemaker) is not properly sending the request body to our server. If you were to send invalid JSON you'd get a different error message (HTTP 400) so it's very likely that the request body is not being sent at all.

lycanthrope7 wrote 5 years ago: 1

Thanks for trying to help guys. I guess I'll just have to admit defeat and keep marking episodes the old fashioned way.

Try 30 days of free premium.