Skip to main content
Solved

Klaviyo Api Upgrade


Forum|alt.badge.img
  • Contributor I
  • 1 reply

I am upgrading my apex code in salesforce for the new version of Klaviyo Api. But when I am trying to run the code authorisation is failing for some reasons. When I use this syntax:  req.setHeader('Authorization', 'Klaviyo-API-Key “My Api Key Hardcoded”');,

I am getting the response but i dont want hardcoded value to give here. while trying this syntax i am getting the error 400 :

 req.setHeader('Authorization','klaviyo_api_key '+ defaults.ApiKey__c);.

Can someone please give me a solution to this.Its urgent.

Best answer by abhijithvs

Hi @coder,

Just wanted to check if you are using the right case here for the prefix to be added in the req.setHeader().

I could see that the syntax you have given here has the prefix incorrect.

 req.setHeader('Authorization','klaviyo_api_key '+ defaults.ApiKey__c);.

The right prefix could be Klaviyo-API-Key

 req.setHeader('Authorization','Klaviyo-API-Key '+ defaults.ApiKey__c);.

Can you try this and let know if this works ?

 

Also as @Kim Strauch pointed out you can log the error and see the message since this is 400.

 

Thanks.

View original
Did this topic or the replies in the thread help you find an answer to your question?

2 replies

Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • June 24, 2024

Hey @coder, can you provide a full error response here, as well as more details on the exact request you’re making? Please do not include your actual private api key. 

A 400 error indicates there’s likely an issue with the way your request payload is structured vs. there being an auth error. I’d expect an auth-related error to manifest with a 401
 


Forum|alt.badge.img+2
  • Problem Solver III
  • 10 replies
  • Answer
  • June 24, 2024

Hi @coder,

Just wanted to check if you are using the right case here for the prefix to be added in the req.setHeader().

I could see that the syntax you have given here has the prefix incorrect.

 req.setHeader('Authorization','klaviyo_api_key '+ defaults.ApiKey__c);.

The right prefix could be Klaviyo-API-Key

 req.setHeader('Authorization','Klaviyo-API-Key '+ defaults.ApiKey__c);.

Can you try this and let know if this works ?

 

Also as @Kim Strauch pointed out you can log the error and see the message since this is 400.

 

Thanks.