Delete promo code


#1

Hi, if I am not mistaken you can only delete :id not body? currently you are expecting to post body but also delete.

I only want to delete one promo code not all at once.


#2

@drew
Hi, I am still waiting for a response?


#3

Hi @handre

You wish to delete one promotional code attached to a promotion?

You should be able to do it with a call like this:

curl -X DELETE https://api.moltin.com/v2/promotions/:id/codes \
     -H "Authorization: Bearer XXXX" \
     -H "Content-Type: application/json" \
     -d $'{
      "data":{
        "type":"promotion_codes",
        "codes": [
          {"code":"ZXY_CBA"}
        ]
      }
    }'

Are you finding that this isn’t the case?


#4

hi @drew.

In the docs you can only delete all the promotion codes that is bound to a promotion.
Is it not possible (it will make more sense as this is the norm throughout your docs), to delete a promotion code through it’s :id?


#5

Hi @handre

I created a promotion on my store with two promotional codes:

curl -X POST \
  https://api.moltin.com/v2/promotions/b5f65310-dc59-46ec-b827-e133c93aa3e3/codes \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: 0e8a1c9a-f926-408a-9bf0-522be0f0c781' \
  -H 'cache-control: no-cache' \
  -d '{
  "data":{
    "type":"promotion_codes",
    "codes": [
      {"code":"ZXY_CBA"},
      {"code":"ABC_XYZ"}
    ]
  }
}'

Then I deleted one of the codes with the following call

curl -X DELETE \
  https://api.moltin.com/v2/promotions/b5f65310-dc59-46ec-b827-e133c93aa3e3/codes \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: c30d8533-5b7f-4a55-aad5-0e0330791224' \
  -H 'cache-control: no-cache' \
  -d '{
  "data":{
    "type":"promotion_codes",
    "codes": [
      {"code":"ZXY_CBA"}
    ]
  }
}' 

if I do a GET on the promotion I have just created and deleted a code from:

curl -X GET \
  https://api.moltin.com/v2/promotions/b5f65310-dc59-46ec-b827-e133c93aa3e3/codes \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: 4596a2d4-1d5d-45ea-afbc-a20ea37238a6' \
  -H 'cache-control: no-cache'

I get the response

{
    "data": [
        {
            "code": "ABC_XYZ"
        }
    ]
}

Only one of the promotional codes has been removed from the promotion, is this what you mean?


#6

@drew
I realised that this is when doing a curl call.

How will I do it when I want to do it via a pure api call? where I can’t add a body like in the example above?


#7

You should be able to use the XMLHttpRequest(); object.

Set the header to application json
xhr.setRequestHeader("Content-type", "application/json");

Then do something like this for the body:

let data = JSON.stringify("data":{"type":"promotion_codes","codes": [{"A_CODE"}]);
xhr.send(data);

#8

@drew here is my ts file:

deletePromoCode(id, deletePromoCode) {
    return this.http.delete(
      `${this.uri}/v2/promotions/${id}/codes`,
      deletePromoCode,
      { headers: new HttpHeaders().set('Authorization', 'Bearer ' + localStorage.getItem('auth')) }
    );
  }

The problem is that the DELETE docs looks like this delete(url, options) which means I can only have 2 arguments not 3. Can’t you make your docs do the following:

https://api.moltin.com /v2/promotions/:id/codes/:id
that will also be more consistent as that is how you go about deleting in the rest of your docs