Getting CORS Error while Integrating FedEx with React Js - reactjs

While working on FedEx integration with React, we are able to get authorization key using Google extension but unable to work on other APIs. All the APIs are perfectly working in postman but not while integration. Tried checking rates and transit times but getting CORS error. I have included the code and error screenshot.Could you please help?
let body = JSON.stringify({
"accountNumber": {
"value": "XXXXXXXXX"
},
"requestedShipment": {
"shipper": {
"address": {
"postalCode": 75063,
"countryCode": "US"
}
},
"recipient": {
"address": {
"postalCode": "L0J 0A0",
"countryCode": "CA"
}
},
"pickupType": "DROPOFF_AT_FEDEX_LOCATION",
"serviceType": "FEDEX_GROUND",
"rateRequestType": [
"LIST",
"ACCOUNT"
],
"customsClearanceDetail": {
"dutiesPayment": {
"paymentType": "SENDER",
"payor": {
"responsibleParty": null
}
},
"commodities": [{
"description": "Camera",
"quantity": 1,
"quantityUnits": "PCS",
"weight": {
"units": "KG",
"value": 20
},
"customsValue": {
"amount": 100,
"currency": "USD"
}
}]
},
"requestedPackageLineItems": [{
"weight": {
"units": "KG",
"value": 20
}
}]
}
});
axios.post("https://apis-sandbox.fedex.com/rate/v1/rates/quotes", body, {
headers : {
"Accept": "*/*",
"Content-Type": "application/json",
"authorization": `Bearer XXX`,
"Access-Control-Allow-Origin": "*",
}
}).then(res => console.log(res.data));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Cors error cannot be solved from front end , cause its a browser error. so You have to create proxy server to solve this
create an API in backend and send request from server to fedex.

Related

Delete Entity on Azure Table Storage from Logic App

I have a requirement to delete old records after X days from Azure Table Storage, so I have created a Logic App for that and run on daily bases to remove old data.
I have use the Get All Entities based on the condition in filter query and then run for each with delete entity in it.
Everything is running fine except the Delete Entity, it is giving 404 Resource Not Found error. I have used the same Partition and Row Key from For Each and also used Etag = * but still it is giving me 404.
Input
{
"method": "delete",
"headers": {
"If-Match": "*"
},
"path": "/Tables/deleteordertest/entities/etag(PartitionKey='2021-09-27T19:16:07.778815Z',RowKey='1')",
"host": {
"connection": {
"referenceName": "azuretables"
}
}
}
Output:
{
"statusCode": 404,
"headers": {
"Cache-Control": "no-cache",
"x-ms-request-id": "11d3c7fe-3002-004a-5ed3-0d0096000000",
"x-ms-version": "2016-05-31",
"X-Content-Type-Options": "nosniff",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "Thu, 20 Jan 2022 08:01:02 GMT",
"Content-Length": "251",
"Content-Type": "application/json"
},
"body": {
"odata.error": {
"code": "ResourceNotFound",
"message": {
"lang": "en-US",
"value": "The specified resource does not exist.\nRequestId:11d3c7fe-3002-004a-5ed3-0d0096000000\nTime:2022-01-20T08:01:02.6479920Z"
}
}
}
}
Working on Postman
If I try same thing in postman then it is working fine, so I don't know what can be the issue here. I have already tried to add and remove encodeURIComponent but no luck.
I doubt about the : in the PartitionKey but it is working while using Replace Entity (Merge), so it cannot be possible that it will work for one item and not for another..
If any one can help me here or guide me for any alternative.
After reproducing from our end found that the reason that you are receiving a 404 status code because of removing encodeURIComponent which will be refering to the entity that we are retrieving. After adding the encodeURIComponent in Get entities action solved the error.
Here is my logic app
Here is the codeview of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Delete_Entity_2": {
"inputs": {
"headers": {
"If-Match": "*"
},
"host": {
"connection": {
"referenceName": "azuretables"
}
},
"method": "delete",
"path": "/Tables/#{encodeURIComponent('Table2408')}/entities/etag(PartitionKey='#{encodeURIComponent(items('For_each')?['PartitionKey'])}',RowKey='#{encodeURIComponent(items('For_each')?['RowKey'])}')"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"foreach": "#body('Get_entities')?['value']",
"runAfter": {
"Get_entities": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_entities": {
"inputs": {
"host": {
"connection": {
"referenceName": "azuretables"
}
},
"method": "get",
"path": "/Tables/#{encodeURIComponent('Table2408')}/entities",
"queries": {
"$filter": "PartitionKey le '5'"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Second",
"interval": 15
},
"type": "Recurrence"
}
}
},
"kind": "Stateful"
}
Here is the output :-

unauthorized with sendgrid smtp

I'm sending emails using sendgrid smtp and always get unauthorized error for the request.
I followed the docs here https://sendgrid.com/docs/for-developers/sending-email/api-getting-started/.
Should I login in from my terminal or something like this?
const sendFunc = () => {
return fetch('https://api.sendgrid.com/v3/mail/send', {
method: 'Post',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {my apiKey-here}'
},
data: { "personalizations": [{ "to": [{ "email": "mahmoudnafea19#gmail.com", "name": "John Doe" }], "subject": "Hello, World!" }], "content": [{ "type": "text/plain", "value": "Heya!" }], "from": { "email": "mahmoud.m.elsayed19#gmail.com", "name": "Sam Smith" }, "reply_to": { "email": "sam.smith#example.com", "name": "Sam Smith" } }
}).then((response) => console.log(response)).catch((err) => console.log(err))
}
I had to pass the data and headers as objects outside the function call

Users added via graph not receiving welcome email

First I tried adding a group owner as both owner and member in the same http call as I created the group:
{
"description": "test group",
"displayName": "test_group",
"groupTypes": [
"Unified"
],
"mailEnabled": true,
"mailNickname": "project.1-TestPreview",
"members#odata.bind": [
"https://graph.microsoft.com/v1.0/users/{id}"
],
"owners#odata.bind": [
"https://graph.microsoft.com/v1.0/users/{id}"
],
"securityEnabled": false,
"visibility": "private"
}
The user is added as a member and owner successfully, but not receiving a welcome email.
I then tried to split the http calls, thinking that there was an issue with the emails as the group was created at the same time as the user was added.
I created the group with one user being added in the creation http call same as above and three other users being added as owner and member ~30 seconds after the group was created. For this I used
queries:
{
"type": "POST",
"url": "https://graph.microsoft.com/v1.0/$batch"
}
body
{
"requests": [
{
"body": {
"#odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
},
"headers": {
"Content-Type": "application/json"
},
"id": "1",
"method": "POST",
"url": "groups/{id}/members/$ref"
},
{
"body": {
"#odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
},
"headers": {
"Content-Type": "application/json"
},
"id": "2",
"method": "POST",
"url": "groups/{id}/members/$ref"
},
{
"body": {
"#odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
},
"headers": {
"Content-Type": "application/json"
},
"id": "3",
"method": "POST",
"url": "groups/{id}/members/$ref"
}
]
}
I added the users as owners with the same method. None of them received a welcome email. How can I make sure that the email fires?
I am doing this in Logic Apps:
You need a proper Microsoft 365, Office 365 or Exchange license. Do you have one?

Different response on similar requests Gmail API

I'm trying to handle the response object from Gmail API with getting attachments from certain messages:
In my Gmail account i have 2 Labels:
Label_1
Label_2
both messages get daily reports from different web services and im using the Gmail API to first get a list of messages while im filtering a message with a Label and a query search string (q field) which contains a certain date (this is how i get only one message when i request a list)
with the response object Im able to get the message ID and then send another request with the message ID.
I want to download the attachments so in the response object im searching for the Payload.Parts field of the response object
In Label_1 response - Payload.Parts[0] contains the filename field and Payload.Parts[0].Body contains the attachmentID
In Label_2 response - Payload.Parts[1].Parts[0] contains the filename and same for .Body contains the attachmentID.
my question is: why this is happening?
why in one response i get the wanted fields in the first Payload.Parts and in the second i have to go deeper in the object's fields?
I've also noticed that in Label_1 response I receive an HTTP header which I dont get on the second one that I think may be related: DKIM-Signature
any thoughts?
Thanks.
The response you get is just the RFC822-message parsed to JSON. The message might be multipart/mixed, multipart/related, text/html or something similar. It is best to write your code so you check all parts in the payload:
var response = {
"payload": {
"parts": [
{
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=001a1142e23c551e8e05200b4be0"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
}
],
"body": {
"size": 9,
"data": "V293IG1hbg0K"
}
},
{
"partId": "0.1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
}
],
"body": {
"size": 30,
"data": "PGRpdiBkaXI9Imx0ciI-V293IG1hbjwvZGl2Pg0K"
}
}
]
},
{
"partId": "1",
"mimeType": "image/jpeg",
"filename": "feelthebern.jpg",
"headers": [
{
"name": "Content-Type",
"value": "image/jpeg; name=\"feelthebern.jpg\""
},
{
"name": "Content-Disposition",
"value": "attachment; filename=\"feelthebern.jpg\""
},
{
"name": "Content-Transfer-Encoding",
"value": "base64"
},
{
"name": "X-Attachment-Id",
"value": "f_ieq3ev0i0"
}
],
"body": {
"attachmentId": "ANGjdJ_2xG3WOiLh6MbUdYy4vo2VhV2kOso5AyuJW3333rbmk8BIE1GJHIOXkNIVGiphP3fGe7iuIl_MGzXBGNGvNslwlz8hOkvJZg2DaasVZsdVFT_5JGvJOLefgaSL4hqKJgtzOZG9K1XSMrRQAtz2V0NX7puPdXDU4gvalSuMRGwBhr_oDSfx2xljHEbGG6I4VLeLZfrzGGKW7BF-GO_FUxzJR8SizRYqIhgZNA6PfRGyOhf1s7bAPNW3M9KqWRgaK07WTOYl7DzW4hpNBPA4jrl7tgsssExHpfviFL7yL52lxsmbsiLe81Z5UoM",
"size": 100446
}
}
]
}
};
// In e.g. a plain text message, the payload is the only part.
var parts = [response.payload];
var attachmentIds = [];
while (parts.length) {
var part = parts.shift();
if (part.parts) {
parts = parts.concat(part.parts);
}
if(part.body && part.body.attachmentId) {
attachmentIds.push(part.body.attachmentId);
}
}
console.log(attachmentIds);

Can I chain multiple actions for every item in a repeat list

tried a simple logic app where I was able to retrieve a list from an API. Using the repeat over a list feature, I was able to send an email for every item in the list.
But I really want to be able to perform several chained actions/steps for every item in the list...isn't that possible? I know I can have multiple actions/steps that perform something for each item in the same list...but these are not chained as in the following code:
"triggers": {
"recurrence": {
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Recurrence"
}
},
"actions": {
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "https://example.com/pcme/3/7",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic my auth"
}
},
"conditions": []
},
"office365connector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector",
"gateway": "https://workflowsxxxxxx.azurewebsites.net"
},
"operation": "SendMail",
"parameters": {
"message": {
"To": "some-email#me.com",
"Subject": "#repeatItem().activationCode"
}
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/xxxxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector/token')"
}
},
"repeat": "#body('http')",
"conditions": [
{
"expression": "#equals(actions('http').status, 'Succeeded')"
}
]
},
"office365connector0": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector",
"gateway": "https://workflowsdxxxx.azurewebsites.net"
},
"operation": "SendMail",
"parameters": {
"message": {
"To": "some-email#gmail.com",
"Subject": "#repeatItem().cardNumber"
}
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/xxxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector/token')"
}
},
"repeat": "#body('http')",
"conditions": [
{
"expression": "#equals(actions('http').status, 'Succeeded')"
}
]
}
Thank you for any help.
Regards
One option for chaining actions over each item in the list is to use a nested logic app.
The way you would set it up is to have a child logic app with a chain of actions that you want to apply to each individual item. The parent logic app would then use the workflow action type in order to invoke a run of the child logic app each of your repeat items.
Your parent workflow would then be defined as
"actions": {
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "https://example.com/pcme/3/7",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic my auth"
}
},
"conditions": []
},
"processEachItem" : {
"type": "workflow",
"inputs": {
"uri": <child flow direct invoke uri>,
"apiVersion": "2015-02-01-preview",
"trigger": {
"name" : "runNow",
"outputs": { "item": "#repeatItem()" }
},
"authentication": {
"type" : " Basic",
"username" : "myKey",
"password" : "xxxxxxxxxxxxxxx",
},
"repeat": "#body('http')",
}
}
}
The following blog post explains the details on how to use nested workflows (how to obtain the direct invoke URI and configure authentication) and has a nice sample: https://blogs.msdn.microsoft.com/carlosag/2015/05/31/using-nested-azure-logic-apps-or-invoking-flows-from-another-logic-app/

Resources