Gravity Forms API always 401

倾然丶 夕夏残阳落幕 提交于 2019-12-05 12:09:34

For mine case it was that I haven't clicked the update button "Web API" Tab.

Make sure you click update button , although it does show the API Key's but still you have to click update button to enable API.

I was getting the same thing due to some weirdness about the route endpoint. When calculating the signature you don't use a trailing slash on the route: forms/1.

But you do use a trailing slash in the URL (otherwise I got a 301 Moved Permanently):

http://demo.gravityforms.com/gravityformsapi/the_route/?api_key...

It looks odd to have /?api_key... but that is what works for me.

Here's the ruby example I was using with the demo credentials:

GravityFormsAPI.generate_URL(site: 'demo.gravityforms.com', route: 'forms/1', public_api_key: '5b225f8382', private_api_key: 'fc6d1bc71d2ebfc')

Hope this helps.

Philippe Michaud

Sometimes i received intermittent 401 error after a lot of research i find this article

Azure DocumentDB Intermittent 401 error when querying REST API via Obj-c

If the signature contains + sign i received 401 error

Maybe that help other person

Sorry for my english writing

Based on the solution here I'm posting this answer.
Imagine you have created the URL and it didn't work and you got 401. Then after a little time you realized the error that Opps! The parameters I was passing needed a bracket and you run the code again and you again got 401. Why is that?

This is because the parameters which are apiKey, Signature and Expire time are the same and you only changed the other parameters with your GET request. However these three parameters are used to authenticate the user so that means the old signature which was generated to deny the permission will deny it again no matter what.

So to fix that I just changed the expire time from 1577922200 to 1577933200. I could've changed it to anything but the thing is I just need to give something new so that a new signature can be generated. So when I changed it started working.

OTHER POSSIBLE REASON

While making the signature using SHA1 you use NSString *string_to_sign = [NSString stringWithFormat:@"%@:%@:%@:%@",api_key,http_method,route,expires]; as per the documentation. But in order to make CCHmac you have to pass it two things:

  1. Key
  2. Data

and based on the link it is created as

const char *cKey  = [api_private_key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [string_to_sign cStringUsingEncoding:NSASCIIStringEncoding]; 

So what I was mistaking is that I was using API Key in cKey instead of API Private Key. So I change it as per tutorial said and it worked. Otherwise I was getting 401 not matter what I try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!