rest-api icon indicating copy to clipboard operation
rest-api copied to clipboard

Cross-Origin Request Blocked

Open inyee786 opened this issue 7 years ago • 11 comments

 headers.append('Authorization', btoa('[email protected],key'));
      headers.append('Access-Control-Allow-Origin', 'https://{{domain}}.agilecrm.com');
      headers.append('Access-Control-Allow-Methods', 'POST');
      headers.append('Access-Control-Max-Age', '86400');

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://aliworkspace.agilecrm.com/dev/api/contacts. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

inyee786 avatar Feb 01 '18 20:02 inyee786

I am facing the same issue, is there a solution to this one?

sahil912 avatar Oct 18 '19 12:10 sahil912

 headers.append('Authorization', btoa('[email protected],key'));
      headers.append('Access-Control-Allow-Origin', 'https://{{domain}}.agilecrm.com');
      headers.append('Access-Control-Allow-Methods', 'POST');
      headers.append('Access-Control-Max-Age', '86400');

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://aliworkspace.agilecrm.com/dev/api/contacts. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Facing the same issue

sahil912 avatar Oct 18 '19 12:10 sahil912

I didn't use the rest-api library, agile have nodejs library you can use that https://github.com/agilecrm/nodejs

inyee786 avatar Oct 20 '19 14:10 inyee786

I want to implement this on front end react app. Is there a way to do it on react app?

sahil912 avatar Oct 21 '19 05:10 sahil912

Please use Agile CRM JS api which takes care of CORS issue.

On Mon, Oct 21, 2019 at 10:54 AM sahil912 [email protected] wrote:

I want to implement this on front end react app. Is there a way to do it on react app?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/agilecrm/rest-api/issues/51?email_source=notifications&email_token=AARBBLIL3ZRCF4AJQNGOQDLQPU4H3A5CNFSM4EOZAD2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBZC3GA#issuecomment-544353688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARBBLNWJK27U2SNCBLJPCDQPU4H3ANCNFSM4EOZAD2A .

agilecrm avatar Oct 21 '19 07:10 agilecrm

Please use Agile CRM JS api which takes care of CORS issue. On Mon, Oct 21, 2019 at 10:54 AM sahil912 @.***> wrote: I want to implement this on front end react app. Is there a way to do it on react app? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#51?email_source=notifications&email_token=AARBBLIL3ZRCF4AJQNGOQDLQPU4H3A5CNFSM4EOZAD2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBZC3GA#issuecomment-544353688>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARBBLNWJK27U2SNCBLJPCDQPU4H3ANCNFSM4EOZAD2A .

Tried to use the JS API to create contact contact is the json object

 axios.post("https://{domain}.agilecrm.com/dev/api/contacts", contact, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',

    },
    auth: {
        username: 'email',
        password: 'api_key'
    }
}).then(response => {
}).catch(error => {
});

Getting the following 401 error, attaching the screenshot:

image

sahil912 avatar Oct 21 '19 09:10 sahil912

@sahil912 you need to add your host to allowed domains in agilecrm admin settings

seleckis avatar Nov 08 '19 09:11 seleckis

I'm facing the same issue while using the NodeJS library. @seleckis Where exactly can one do that? Can you share a screenshot. Did you mean Admin Settings -> Preferences -> Security (to add IPs). FYI: I have a free account if that matters

andyfaizan avatar Mar 26 '20 16:03 andyfaizan

@andyfaizan Admin Settings -> Analytics -> Allowed Domains

seleckis avatar Mar 26 '20 18:03 seleckis

Still doesn't work unfortunately. I can cURL the API and it works since the cURL sends a direct POST request whereas the browser sends an OPTIONS request first and it goes through the auth and gets a 401. OPTIONS should always be allowed on the server side.

andyfaizan avatar Mar 27 '20 10:03 andyfaizan

any updates?

goerkemballmueller avatar Feb 11 '24 19:02 goerkemballmueller